Jump to content

[SOLVED] gah, php search returning 0 results!


wickedawsome

Recommended Posts

ok, sorry to be asking such an easy question again but ive been trying for 2 hours and it still is not returning any results.  I can see my table and there is clearly items of the exact name in it, its just not being returned.

 

 

connectDb();


$searchin = $_POST['searchin']; //takes in text from other page
//print("$search"); //was a test, came back right

//error message (not found message) 
$XX = "No Record Found"; 
$query = mysql_query("SELECT * FROM $table WHERE 'firstname' LIKE '%$searchin%' OR 'lastname' LIKE '%$searchin%'"); 
while ($row  = mysql_fetch_array($query))
   { 
        $variable1=$row["id"]; 
        $variable2=$row["firstname"]; 
        $variable3=$row["lastname"]; 
print ("$variable1, $variable2, $variable3, '<br>'");  
   } 

//below this is the function for no record!! //this is being tripped every time
if (!$variable1)  
{ 
print ("$XX"); 
print(" for $searchin");//another test...fine
} 
//end 
?>

 

 

not sure whats going on here, please help.  Thanks

 

gary

$query = mysql_query("SELECT * FROM $table WHERE 'firstname' LIKE '%$searchin%' OR 'lastname' LIKE '%$searchin%'"); 
if(mysql_num_rows($query){
   while ($row  = mysql_fetch_array($query)){
      $variable1=$row["id"]; 
      $variable2=$row["firstname"]; 
      $variable3=$row["lastname"]; 
      print ("$variable1, $variable2, $variable3, <br>");  
   } 
}else{
   print ("$XX"); 
   print(" for $searchin");//another test...fine
} 

change

$query = mysql_query("SELECT * FROM $table WHERE 'firstname' LIKE '%$searchin%' OR 'lastname' LIKE '%$searchin%'"); 

to

$query = mysql_query("SELECT * FROM $table WHERE 'firstname' LIKE '%$searchin%' OR 'lastname' LIKE '%$searchin%'") or die(mysql_error());

change:

 

$query = mysql_query("SELECT * FROM $table WHERE 'firstname' LIKE '%$searchin%' OR 'lastname' LIKE '%$searchin%'"); 

 

to:

 

$query = mysql_query("SELECT * FROM $table WHERE 'firstname' LIKE '%$searchin%' OR 'lastname' LIKE '%$searchin%'") or die(mysql_error());

 

and see what the error is.

 

I'm putting my money on the single quotes around your table name.  That is supposed to be a back-tic ( ` ) not a single quote ( ' ).

The correct syntax would be....

 

<?php

  connectDb();
  $searchin = $_POST['searchin'];
  $sql = "SELECT * FROM $table WHERE firstname LIKE '%$searchin%' OR lastname LIKE '%$searchin%'"
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result) {
      while ($row = mysql_fetch_array($result)) {
        $variable1 = $row["id"]; 
        $variable2 = $row["firstname"]; 
        $variable3 = $row["lastname"]; 
        print "$variable1, $variable2, $variable3, <br>";  
      } 
    } else {
     print "No results found";
  } else {
    print "Query failed : $sql"
  }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.