开发者

Issue with mysql search results

Everything pretends to work great, except when I Search for anything I get no results with no errors. I think my issue is within my query, but I can seem to pinpoint it. I have made some searches before, but only linking 2 开发者_Go百科tables. Now that I am trying to Link 4 tables, it got pretty complicated. I would like to get a clarification on what I may need to adjust to clear this mess up.

    <?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>";
}
?>


Resolved...

instead of

JOIN sptraining ON sprecord.sptraining_id = sptraining.trainingtype JOIN splocation ON spusername.splocation_id = splocation.location

I mistakenly said it equaled the trainingtype and location instead of id.

example of it working: JOIN sptraining ON sprecord.sptraining_id = sptraining.id JOIN splocation ON spusername.splocation_id = splocation.id

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜