我是 PHP 和 mysql 的新手。我的项目就像生物“字典”。我想找到一个 WORD,我会得到它的定义和更多列,其中包含有关我正在寻找的 WORD 的相关信息。我想在漂亮的表中获取字典数据。
我编写了查询以从我的 mysql 数据库中检索与我的单词相关的数据。我将从 4 个不同的表中获取数据。
我已经编写了 Index.php 和 data.php 代码,发布在下面。问题>>>>>>
1) 当我运行 inded.php 文件时出现错误
function get() { $.post ('data.php', { word: form.name.value }, function (output) { $('#defination') .html(output).show() ; }); } "
2)我很难为data.php文件编写代码,请给我建议。我正在从多个表中检索数据,因此非常混乱。
请帮帮我,我真的很挣扎,我会很感激你的帮助。
谢谢
索引.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"
<html lang="en">
<head>
<title></title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript"></script>
function get() {
$.post ('data.php', { word: form.name.value },
function (output) {
$('#defination') .html(output).show() ;
});
}
</head>
<body>
<p>
<form name ="form">
<input type="search" name="name" size = "30" placeholder="Please enter the Word">
<input type="button" value="Get" onClick="get();">
</form>
<div id="defination"> </div>
</p>
</body>
</html>
数据.php
<table border="2" cellpadding="5" cellspacing="1" bordercolor="#000000">
<tr>
<!--<td width="120"><b>Normalized Word</b></td>
<td width="120"><b>Normalized String</b></td>-->
<td width="120"><b>Word</b></td>
<td width="120"><b>Defination</b></td>
<td width="120"><b>Type of Sementic</b></td>
<td width="120"><b>Source</b></td>
</tr>
<tr>
<td>
<?php
$username = "root";
$password = "";
$hostname = "127.0.0.1";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db("umls",$dbhandle)
or die("Could not select examples");
// $_Post
$name = mysql_real_escape_string($_POST['word']);
//Name is NULL
if ($word==NULL)
echo "Please enter a Word" ;
else {
// Do Query
$result = mysql_query("SELECT DISTINCT * FROM nString WHERE Normalized_String= '$word' GROUP by string, defination, Source");
$result_num_rows = mysql_num_rows($result);
//fetch tha data from the database
while ($row = @mysql_fetch_array($result))
{
$variable1=$row["Normalized_Word"];
$variable2=$row["Normalized_String"];
$variable3=$row["String"];
$variable4=$row["Defination"];
$variable5=$row["Semantic_type"];
$variable6=$row["source"];
//table layout for results
print ("<tr>");
//print ("<td>$variable1</td>");
//print ("<td>$variable2</td>");
print ("<td>$variable3</td>");
print ("<td>$variable4</td>");
print ("<td>$variable5</td>");
print ("<td>$variable6</td>");
print ("</tr>");
}
}
// while ($row = mysql_fetch_array($result)) {
// echo $row{'CUI'}.$row{'SUI'}.$row{'AUI'}."<br>";
//close the connection
mysql_close($dbhandle);
?>
</table>