我是Php和mysql的新手。我的項目就像生物「詞典」。我想找到一個WORD,我會得到它的定義和更多的列,其中有關於我尋找的WORD的相關信息。我想獲得漂亮的表格中的字典數據。我如何在PHP中使用Jquery時編寫查詢代碼
我已經寫了查詢來從我的mysql數據庫中檢索與我的單詞有關的數據。我將從4個不同的表中獲取數據。
我寫了下面發佈的Index.php和data.php代碼。問題>>>>>>
1)當我運行inded.php文件I m如果我有在data.php文件寫入代碼難於錯誤
function get() { $.post ('data.php', { word: form.name.value }, function (output) { $('#defination') .html(output).show() ; }); } "
2),請給我建議。我從多個表中檢索數據,所以它很混亂。
請幫助我,我真的很掙扎,我會感謝您的幫助。
謝謝
的index.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>
data.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>
是一個PHP錯誤信息? – 2013-07-23 20:47:17