wickedawsome Posted February 14, 2007 Share Posted February 14, 2007 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 14, 2007 Share Posted February 14, 2007 $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 } Quote Link to comment Share on other sites More sharing options...
fert Posted February 14, 2007 Share Posted February 14, 2007 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()); Quote Link to comment Share on other sites More sharing options...
trq Posted February 14, 2007 Share Posted February 14, 2007 $query = mysql_query("SELECT * FROM $table WHERE firstname LIKE '%$searchin%' OR lastname LIKE '%$searchin%'"); Also, you really ought to check the query was successful and returns results before trying to use it. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 14, 2007 Share Posted February 14, 2007 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 ( ' ). Quote Link to comment Share on other sites More sharing options...
trq Posted February 14, 2007 Share Posted February 14, 2007 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" } ?> Quote Link to comment Share on other sites More sharing options...
wickedawsome Posted February 14, 2007 Author Share Posted February 14, 2007 thorpe, thanks, there was a ) missing and then it worked perfect to everyone else, I was still recieving no results, not sure why tho thanks to everyone for the amazingly fast response. I love this place! Quote Link to comment Share on other sites More sharing options...
trq Posted February 14, 2007 Share Posted February 14, 2007 I was still recieving no results, not sure why tho You had single quotes around your field names. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.