0
一切假裝工作很好,除非我搜索任何東西,我沒有得到任何結果沒有錯誤。我認爲我的問題在我的查詢範圍內,但我似乎可以指出這一點。我之前做了一些搜索,但只連接了2個表格。現在我正在嘗試鏈接4個表格,它非常複雜。我想澄清一下我可能需要做些什麼來調整以清除這些混亂。mysql問題與搜索結果
<?php
$search = $_GET['search'];
if (!$search)
echo "You didn't enter a keyword";
else
{
echo "<td>You searched for: <strong>$search </strong></td><br><br>";
mysql_connect('localhost','myuserexample','mypassexample');
mysql_select_db('spusers');
[email protected]$_GET['id'];
$query="
SELECT
spusername.id, spusername.firstname, spusername.lastname, spusername.splocation_id,
sptraining.id, sptraining.trainingtype, sptraining.level,
splocation.id, splocation.location,
sprecord.spusername_id, sprecord.sptraining_id
FROM spusername
JOIN sprecord ON spusername.id = sprecord.spusername_id
JOIN sptraining ON sprecord.sptraining_id = sptraining.trainingtype
JOIN splocation ON spusername.splocation_id = splocation.location
WHERE MATCH (firstname, lastname, trainingtype, level, location, spusername_id, sptraining_id, splocation_id)
AGAINST('%".$search."%' IN BOOLEAN MODE) ORDER BY lastname ASC";
$result1 = MySQL_query($query);
if(!$result1) {
echo MySQL_error()."<br>$query<br>";
}
if (MySQL_num_rows($result1) > 0) {
echo "<table class='sortable' width='750' align='center' border='1' bordercolor='#000000' bgcolor='#000000'
cellspacing='2' cellpadding='2'><tr><th bgcolor=#999999>
Employee</th><th bgcolor=#999999>
Location</th><th bgcolor=#999999>
Training</th><th bgcolor=#999999>
Level</a></th><th bgcolor=#999999>
Date Completed</th></tr bgcolor=#999999>";
while($result2 = MySQL_fetch_array($result1)) {
echo "<td bgcolor=#d4d5ff>{$result2['lastname']},
{$result2['firstname']}</td><td bgcolor=#d4d5ff>
{$result2['location']}</td><td bgcolor=#d4d5ff>
{$result2['trainingtype']}</td><td bgcolor=#d4d5ff>
{$result2['level']}</td></tr>";
}
echo "</table>";
} else {
echo "No Results were found in this category.<br>";
}
echo "<br>";
}
?>
做了一些修改,我刪除了一些測試中,我做到了,並把它回我的原始格式 – asar
除了代碼中的大量SQL注入漏洞,你會得到什麼錯誤?或者它只是返回你沒有想到的數據? –
第一步是刪除where子句並可能添加限制1,以確保您的連接正常工作。這樣你就會知道你正在搜索的recodset存在 – horatio