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

Link to comment
Share on other sites

$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
} 

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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 ( ' ).

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.