2011-09-16 3 views
0

Tout fait semblant de fonctionner très bien, sauf quand je cherche n'importe quoi je n'obtiens aucun résultat sans erreur. Je pense que mon problème est dans ma requête, mais je peux sembler le localiser. J'ai fait quelques recherches auparavant, mais en reliant seulement 2 tables. Maintenant que j'essaye de relier 4 tables, ça devient assez compliqué. J'aimerais obtenir une précision sur ce que je devrais peut-être ajuster pour régler ce problème.Problème avec les résultats de recherche 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>"; 
} 
?> 
+0

certains ont-ils l'édition, je l'ai enlevé quelques tests, je l'ai fait, et la remettre à mon format original – asar

+5

Autre que l'énorme trou d'injection SQL dans votre code, quelle erreur obtenez-vous? Ou est-ce simplement le retour de données auxquelles vous ne vous attendiez pas? –

+1

la première étape consiste à supprimer la clause where et peut-être ajouter la limite 1 afin que vous puissiez vous assurer que vos jointures fonctionnent. De cette façon, vous savez que le recodset que vous recherchez n'existe pas – horatio

Répondre

0

Résolu ...

au lieu de

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

je l'ai dit par erreur égalait le type de formation et l'emplacement au lieu de id.

exemple de ce travail: REJOIGNEZ sptraining ON sprecord.sptraining_id = sptraining.id REJOIGNEZ splocation ON spusername.splocation_id = splocation.id

Questions connexes