Branden Wagner Posted July 23, 2006 Share Posted July 23, 2006 $keytype = "LastName";$keyword = "Smith";$result= mysql_query("SELECT * from Customers where $keytype like '%". $keyword ."%'");if i use it like that it returns both entries as it should for both bob and john smith.however if i search..$keyword = "Smi";or any other partial match it returns nothing.. what am i doing wrong? and what do i need to do SQL wildcards i thought % was a wildcard. Quote Link to comment Share on other sites More sharing options...
hvle Posted July 23, 2006 Share Posted July 23, 2006 yes, there's nothing wrong, and yes, it should return the same result as with 'Smith' or 'smith' or 'smi'.I think something else is wrong. Quote Link to comment Share on other sites More sharing options...
Branden Wagner Posted July 23, 2006 Author Share Posted July 23, 2006 [code]function find_customer($keytype,$keyword){ //Conect to DB mysql_connect($db_host, $db_user, $db_pass); mysql_select_db("$db_name") or die(mysql_error()); switch($keyword) { case "CustomerID": case "PhoneNumber": $result= mysql_query("SELECT * from Customers where $keytype='". $keyword ."'"); break; case "FirstName": case "LastName": case "CompanyName": $result= mysql_query("SELECT * from Customers where $keytype like '%". $keyword ."%'"); break; default: $result= mysql_query("SELECT * from Customers where $keytype='$keyword'"); break; } while($row = mysql_fetch_assoc($result)) { $customer[] = array( $row['CustomerID'], $row['FirstName'],$row['LastName'] ); } return $customer;}[/code]well theres my whole query function.. also i just ran the query from MySQL command line and your right it does work the way it should... but its not here(in php). suggestions? Quote Link to comment Share on other sites More sharing options...
hvle Posted July 23, 2006 Share Posted July 23, 2006 you should switch $keytype instead of $keyword:change switch($keyword)to switch($keytype) Quote Link to comment Share on other sites More sharing options...
Branden Wagner Posted July 23, 2006 Author Share Posted July 23, 2006 I HATE YOU ;Dlol... i knew there was something simple.. Thanks... that did it. 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.