Page 1 of 1

mysql search table query

Posted: Fri Jan 29, 2010 2:25 pm
by me666
the following code will search different collums in my table ok, but if i search for 'joe bloggs' it will return no result as joe is in collum1 and bloggs in collum2. any ideas how i would code it to find it?

Code: Select all

<?php
$result = mysql_query("SELECT * FROM profileu WHERE email = '$qry' or firstname LIKE '%$qry%' or lastname LIKE '%$qry%'");
while($row = mysql_fetch_object($result)) {
print "$row->firstname";
print "<br>";
}
?>

Re: mysql search table query

Posted: Fri Jan 29, 2010 2:41 pm
by AbraCadaver

Code: Select all

$result = mysql_query("SELECT * FROM profileu WHERE email = '$qry' or firstname LIKE '%$qry%' or lastname LIKE '%$qry%'
                        OR CONCAT_WS(' ', firstname, lastname) LIKE '%$qry%'");

Re: mysql search table query

Posted: Fri Jan 29, 2010 3:25 pm
by me666
excellent, thank you very much AbraCadaver, much appreciated :D

Re: mysql search table query

Posted: Sat Jan 30, 2010 5:16 am
by me666
thank you, had to change it slightly, the CONCAT_WS still returned nothing, so i put that after the email = '$qry' and now works fine :D