mysql search table query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
me666
Forum Commoner
Posts: 87
Joined: Wed Oct 08, 2008 5:04 pm

mysql search table query

Post 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>";
}
?>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: mysql search table query

Post 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%'");
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
me666
Forum Commoner
Posts: 87
Joined: Wed Oct 08, 2008 5:04 pm

Re: mysql search table query

Post by me666 »

excellent, thank you very much AbraCadaver, much appreciated :D
me666
Forum Commoner
Posts: 87
Joined: Wed Oct 08, 2008 5:04 pm

Re: mysql search table query

Post 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
Post Reply