老师布置的作业全文如下:
参考http://162.105.80.203/odbc_example.php和通讯录的例子, 实现一个网页, 可以查询在'semantic'数据库的'60'表中某个词的相关情况
用户可以在网页上对一组词的相关情况投赞成票, 赞成票保存在'semantic'数据库的'user'表中.
查询结果应综合原'60'表中给出的数据和用户的投票结果进行展示
提示, 综合两个表中的数据可以在php中完成, 也可以在javascript中完成. php和javascript可以通过任意方式交互, 不局限与json.'semantic'数据库中'60'表包含字段如下:ID: 每个字段的唯一编号
word1: 词1
attr1: 词1的词性
word2: 词2
attr2: 词2的词性
relation: 相关度
表中的每一个记录表示词1和词2之间的相关度为relation字段中的值. 表60中的中文使用GBK编码.'user'表包含字段如下:ID: 每个字段的唯一编号
word1: 词1
word2: 词2
每一个记录代表曾经有用户对word1和word2之间的相关性投一次赞成票.
--------------------------------------------------------------------------
先说第一个,查询问题我的php代码和html代码分别如下:
<?php
$conn=odbc_connect('semantic','','');if (!$conn) echo "Connection Failed";
else {
if (isset($_GET['query']))
{
$a=$_GET['query'];
$result=odbc_exec($conn,"Select * From 60 where word1='$a' "); echo "[";
$i=0;
while (odbc_fetch_row($result) && $i<30)
{
$x1=odbc_result($result,"word1");
$x2=odbc_result($result,"word2");
$id=odbc_result($result,"ID");
$r=odbc_result($result,"relation");
echo "{'id':'$id','word1':'$x1','word2':'$x2','relation':'$r'},";
$i=$i+1;
}
echo "]\n";
}
}
odbc_close($conn);
?><html>
<meta charset="gbk" /><title>Test</title><head>
<script type="text/javascript">
function found(str)
{
var query=document.getElementById("word");
var wait=document.getElementById("blank");
wait.innerHTML="Waiting......";
if (str.length==0)
{
wait.innerHTML="";
return true;
}
var xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
if (xmlhttp.status==200) {
wait.innerHTML="";
var words=eval("("+xmlhttp.responseText+")");
var newtable=document.creatElement("table"); newtable.innerHTML="<tr><td>ID</td><td>词语1</td><td>词语2</td>"+
"<td>相关度</td></tr>";
for (var i in words)
{
var tr=document.creatElement("tr");
var td=document.creatElement("td");
td.innerHTML=words[i].ID;
tr.appendChild(td);
td.innerHTML=words[i].word1;
tr.appendChild(td);
td.innerHTML=words[i].word2;
tr.appendChild(td);
td.innerHTML=words[i].relation;
newtable.appendChild(tr);
}
}
if (xmlhttp.responseText=="Connection Failed") {
wait.innerHTML="Connection Failed";return;}
}
}
xmlhttp.open("GET","search.php?query="+str,true);
xmlhttp.send(null);
return true;
}</script>
</head><body>
<center>
<h1><b>词汇关系度查询</b></h1>
<p><form>
查询这个词汇:<input id="word" type="text" onkeyup="found(this.value)" />
</form><div id="blank">
</div></center>
</body>
</html>但是无论输入什么,都只会显示waiting......
是不是哪个代码出问题了?。,。。
参考http://162.105.80.203/odbc_example.php和通讯录的例子, 实现一个网页, 可以查询在'semantic'数据库的'60'表中某个词的相关情况
用户可以在网页上对一组词的相关情况投赞成票, 赞成票保存在'semantic'数据库的'user'表中.
查询结果应综合原'60'表中给出的数据和用户的投票结果进行展示
提示, 综合两个表中的数据可以在php中完成, 也可以在javascript中完成. php和javascript可以通过任意方式交互, 不局限与json.'semantic'数据库中'60'表包含字段如下:ID: 每个字段的唯一编号
word1: 词1
attr1: 词1的词性
word2: 词2
attr2: 词2的词性
relation: 相关度
表中的每一个记录表示词1和词2之间的相关度为relation字段中的值. 表60中的中文使用GBK编码.'user'表包含字段如下:ID: 每个字段的唯一编号
word1: 词1
word2: 词2
每一个记录代表曾经有用户对word1和word2之间的相关性投一次赞成票.
--------------------------------------------------------------------------
先说第一个,查询问题我的php代码和html代码分别如下:
<?php
$conn=odbc_connect('semantic','','');if (!$conn) echo "Connection Failed";
else {
if (isset($_GET['query']))
{
$a=$_GET['query'];
$result=odbc_exec($conn,"Select * From 60 where word1='$a' "); echo "[";
$i=0;
while (odbc_fetch_row($result) && $i<30)
{
$x1=odbc_result($result,"word1");
$x2=odbc_result($result,"word2");
$id=odbc_result($result,"ID");
$r=odbc_result($result,"relation");
echo "{'id':'$id','word1':'$x1','word2':'$x2','relation':'$r'},";
$i=$i+1;
}
echo "]\n";
}
}
odbc_close($conn);
?><html>
<meta charset="gbk" /><title>Test</title><head>
<script type="text/javascript">
function found(str)
{
var query=document.getElementById("word");
var wait=document.getElementById("blank");
wait.innerHTML="Waiting......";
if (str.length==0)
{
wait.innerHTML="";
return true;
}
var xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
if (xmlhttp.status==200) {
wait.innerHTML="";
var words=eval("("+xmlhttp.responseText+")");
var newtable=document.creatElement("table"); newtable.innerHTML="<tr><td>ID</td><td>词语1</td><td>词语2</td>"+
"<td>相关度</td></tr>";
for (var i in words)
{
var tr=document.creatElement("tr");
var td=document.creatElement("td");
td.innerHTML=words[i].ID;
tr.appendChild(td);
td.innerHTML=words[i].word1;
tr.appendChild(td);
td.innerHTML=words[i].word2;
tr.appendChild(td);
td.innerHTML=words[i].relation;
newtable.appendChild(tr);
}
}
if (xmlhttp.responseText=="Connection Failed") {
wait.innerHTML="Connection Failed";return;}
}
}
xmlhttp.open("GET","search.php?query="+str,true);
xmlhttp.send(null);
return true;
}</script>
</head><body>
<center>
<h1><b>词汇关系度查询</b></h1>
<p><form>
查询这个词汇:<input id="word" type="text" onkeyup="found(this.value)" />
</form><div id="blank">
</div></center>
</body>
</html>但是无论输入什么,都只会显示waiting......
是不是哪个代码出问题了?。,。。
说明程序没有调用 xmlhttp.onreadystatechange方法。也就是说ajax请求失败。
还有$result=odbc_exec($conn,"Select * From 60 where word1='$a' ");这里是不是要用like进行模糊查询呀?