찾다
php教程PHP源码ajax,php和MySQL实现带Suggest功能的在线英语词典

1. [代码][PHP]代码    

<?
include "linkdb.php";
header("Content-type:text/html;charset=utf-8");
$word=$_GET["word"];
$search=$_GET["searc"];
$sqlstr="SELECT * from word where word=&#39;".$word."&#39;";
$rst=mysql_query($sqlstr);
list($word,$exp)=mysql_fetch_row($rst);
echo &#39;
<em>&#39;.$word.&#39;</em><br/><p>&#39;.$exp.&#39;</p>
&#39;;
if($word==&#39;&#39;){
echo &#39;
<p>查无记录……</p>
&#39;;
	}
?>


2. [代码][PHP]代码

<?
/////////linkdb.php//////////
/////////link database///////
$mydb=mysql_pconnect(&#39;localhost&#39;,&#39;root&#39;,&#39;lijun&#39;);
mysql_query("SET NAMES &#39;utf8&#39;");
if(!$mydb)
{
	//echo "连结失败....";
}else{
	//echo "连接成功....";
}
$db=mysql_select_db(&#39;mydatautf8&#39;,$mydb);
if($db){
	//echo "数据库连接正确...";
}else{
	//echo "数据库连结错误....";
}
?>


3. [文件]     dicsug.php 

<?
///////////词典suggest响应页面/////////////
include "linkdb.php";
header("Content-type:text/html;charset=gb2312");
$word=$_GET["word"];
$sqlstr="SELECT word from word where word like &#39;".$word."%&#39;";
$rst=mysql_query($sqlstr);
$i=0;
$w[&#39;0&#39;]=&#39;&#39;;
$w[&#39;1&#39;]=&#39;&#39;;
$w[&#39;2&#39;]=&#39;&#39;;
$w[&#39;3&#39;]=&#39;&#39;;
$w[&#39;4&#39;]=&#39;&#39;;
$w[&#39;5&#39;]=&#39;&#39;;
$w[&#39;6&#39;]=&#39;&#39;;
$w[&#39;7&#39;]=&#39;&#39;;
$w[&#39;8&#39;]=&#39;&#39;;
$w[&#39;9&#39;]=&#39;&#39;;
while(($row=mysql_fetch_row($rst))&&$i<=9){
	list($w[&#39;&#39;.$i.&#39;&#39;])=mysql_fetch_row($rst);
	$i++;
	}
echo $w["0"].&#39; &#39;.$w["1"].&#39; &#39;.$w["2"].&#39; &#39;.$w["3"].&#39; &#39;.$w["4"].&#39; &#39;.$w["5"].&#39; &#39;.$w["6"].&#39; &#39;.$w["7"].&#39; &#39;.$w["8"].&#39; &#39;.$w["9"];
?>


4. [代码][PHP]代码   

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>四级查词</title>
<style type="text/css">
#inputf {
	position: absolute;
	left: 10px;
	top: 9px;
	width: 419px;
	height: 33px;
	z-index: 1;
	border: #CCC 2px solid;
}
#word {
	background-color: #FFF;
	width:418px;
	height:32px;
	border:hidden 0;
	font-family:微软雅黑,Arial;
	font-size:24px;
}
#suggest {
	position: absolute;
	left: 10px;
	top: 46px;
	width: 421px;
	height: 273px;
	z-index: 3;
	border-right: #999 1px solid;
	border-bottom: #999 1px solid;
	border-left: #999 1px solid;
	font-size: 16px;
	font-family: 微软雅黑,Arial;
	visibility: hidden;
	cursor: default;
}
#outerf {
	position: absolute;
	margin: -100 auto;
	width: 605px;
	height: 300px;
	z-index: 2;
	border-radius: 10px;
	border: #0CF 1px solid;
	left: -76px;
	top: 59px;
	visibility: visible;
}
#rstf em{
	font-size:18px;
	font-family:Arial, Helvetica, sans-serif;
	color:#06F;
	}
#rstf p{
	font-family:楷体,微软雅黑;
	font-size:18px;
	}
#btn {
	position: absolute;
	left: 448px;
	top: 6px;
	width: 40px;
	height: 40px;
	z-index: 6;
	border-radius: 20px;
	background-image: url(image/%E6%90%9C.gif);
	background-position: 0 0;
	visibility: visible;
}
#main {
	position: relative;
	margin:0 auto;
	width: 442px;
	height: 366px;
	z-index: 5;
}
#rstf {
	position: absolute;
	left: 17px;
	top: 11px;
	width: 572px;
	height: 279px;
	z-index: 6;
}
#bt {
	position: absolute;
	left: 454px;
	top: 15px;
	width: 30px;
	height: 22px;
	z-index: 4;
	visibility: hidden;
}
</style>
<script type="text/javascript">
function init(){
	document.getElementById("btn").style.visibility=&#39;visiable&#39;;
	document.getElementById("bt").disabled=false;
	}
</script>
</head>

<body onload="init()">
<p id="main">
    <p id="suggest">
      <table width="421" height="273" border="0">
        <tr id="10" onmouseover="float(this)">
          <td id="0"> </td>
        </tr>
        <tr id="11" onmouseover="float(this)">
          <td id="1"> </td>
        </tr>
        <tr id="12" onmouseover="float(this)">
          <td id="2"> </td>
        </tr>
        <tr id="13" onmouseover="float(this)">
          <td id="3"> </td>
        </tr>
        <tr id="14" onmouseover="float(this)">
          <td id="4"> </td>
        </tr>
        <tr id="15" onmouseover="float(this)">
          <td id="5"> </td>
        </tr>
        <tr id="16" onmouseover="float(this)">
          <td id="6"> </td>
        </tr>
        <tr id="17" onmouseover="float(this)">
          <td id="7"> </td>
        </tr>
        <tr id="18" onmouseover="float(this)">
          <td id="8"> </td>
        </tr>
        <tr id="19" onmouseover="float(this)">
          <td id="9"> </td>
        </tr>
      </table>
    </p>
    <p id="outerf">
        <p id="rstf"></p>
    </p>
    <p id="btn" onmouseover="btnani()" onclick="searchw()"></p>

      <p id="inputf">
        <label for="word"></label>
        <input type="text" onkeyup="suggest()" name="word" id="word" value="" />
      </p>
      

</p>
</body>
</html>
<script type="text/javascript">
var msInSug=0;
function doit(str){
	//用正则表达式将获取是数据提取为数组或变量组并且填充到相应的表格内
	reg=/\b\w+\b/g;
	var arr=str.match(reg);
	for(i=0;i<10;i++){
		document.getElementById(&#39;&#39;+i+&#39;&#39;).innerHTML=(arr[i]=(arr[i])?arr[i]:&#39;&#39;)+&#39;&#39;;
		}
	}
function float(obj){
	obj.style.backgroundColor="#CCC";
	obj.onmouseout=function(){
		obj.style.backgroundColor="";
		};
	mschoose(obj);
	}
function suggest(){
	try{xmlhttp=new XMLHttpRequest;}catch(e){
		try{xmlhttp=new ActiveXObject("microsoft,xmlhttp");}catch(e){
			xmlhttp=new ActiveXObject("msxml2,xmlhttp");
			}
		}
	var word=document.getElementById("word").value;
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4&&xmlhttp.status==200){
			doit(xmlhttp.responseText);
			}
		};
	xmlhttp.open("GET","dicsug.php?word="+word);
	xmlhttp.send();
	document.getElementById("suggest").onmouseover=function(){msInSug=1};
	document.getElementById("suggest").style.visibility=&#39;visible&#39;;
	document.getElementById("word").onblur=function(){
		if(msInSug==1){
			document.getElementById("suggest").style.visibility=&#39;hidden&#39;;
			}
		}
	}
//////////鼠标离开Sug/////////
function msoutsug(){
	msInSug=0;
	}
//////////鼠标选择////////////
function mschoose(ite){
	//各建议项的click事件
	//alert("事件来自:"+ite);
	//正则处理
	var str=ite.innerHTML;
	var reg1=/>\w+</;
	var str1=str.match(reg1);
	str1+=&#39;&#39;;//匹配结果不能直接拿来当作被匹配字符串,要先将其转换为字符串
	var reg2=/\w+/;
	var str2=str1.match(reg2);
	document.getElementById("word").value=(str2=(str2==&#39;null&#39;)?&#39;&#39;:str2);//////////////
	}
///////开始查询//////////////
///////////////////////////
function searchw(){
	check();
	var word=document.getElementById("word").value;
	try{xmlhttp1=new XMLHttpRequest;}catch(e){
		try{xmlhttp1=new ActiveXObject(&#39;microsoft,xmlhttp&#39;);}catch(e){
			xmlhttp1=new ActiveXObject(&#39;msxml2,xmlhttp&#39;);
			}
		}
	xmlhttp1.onreadystatechange=function(){
		if(xmlhttp1.readyState==4&&xmlhttp1.status==200){
			document.getElementById("rstf").innerHTML=xmlhttp1.responseText;
			}
		};
	xmlhttp1.open("GET","dictionary.php?searc=search&word="+word);
	xmlhttp1.send();
	}
</script>
<script type="text/javascript">
function btnani(){
	document.getElementById("btn").style.backgroundPosition=&#39;-40px 0&#39;;
	document.getElementById("btn").onmouseout=function(){this.style.backgroundPosition=&#39;0 0&#39;;}
	}
function check(){
	if(document.getElementById("word").value==&#39;&#39;){
		alert("请输入单词!");
		return false;
		};
	}
</script>
<script type="text/javascript">
t=10;
	function bodyonload(){
		if(event.keyCode==13){
			document.getElementById("btn").onclick;
			}else if(event.keyCode==40){
				if(t>19){t=19;}
				var ite=document.getElementById(t+&#39;&#39;);
				t++;
				float(ite);
				document.getElementById(t+&#39;&#39;).onmouseout;
				}else if(event.keyCode==38){
					if(t<10){t=10;}
					var ite=document.getElementById(t+&#39;&#39;);
					t--;
					}
		}
</script>

           

5. [图片] printscreen1.png    

           

ajax,php和MySQL实现带Suggest功能的在线英语词典

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace("&nbsp;","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

PhpStorm 맥 버전

PhpStorm 맥 버전

최신(2018.2.1) 전문 PHP 통합 개발 도구

안전한 시험 브라우저

안전한 시험 브라우저

안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

SublimeText3 영어 버전

SublimeText3 영어 버전

권장 사항: Win 버전, 코드 프롬프트 지원!

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)