mysql搜索结果的问题


Issue with mysql search results

一切看起来都很好,除了当我搜索任何东西时,我没有得到任何结果,也没有错误。我认为我的问题在我的问题范围内,但我似乎可以精确地指出它。我以前做过一些搜索,但只链接2个表。现在我要链接4个表,它变得相当复杂。我希望得到一个澄清,我可能需要调整什么来清理这个烂摊子。

    <?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');  
  $id=@$_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>";
}
?>

已解决…

不是

JOIN sptraining ON sprecord。Sptraining_id = sptraining.trainingtype在spusername上加入splocation。Splocation_id = splocation.location

我错误地说它等于训练类型和位置,而不是id。

工作的例子:加入sprecord上的训练。Sptraining_id = sptraining.id在spusername上加入splocation。Splocation_id = splocationid