Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

question about mysql_query

Codes here !

Moderators: macek, egami, gesf

question about mysql_query

Postby cledus » Thu Jun 07, 2012 6:09 am

Hello!

I just started looking at php and mysql. I ran into a small problem. I would like to extract data like this: $queryPerson = 'SELECT * FROM persons WHERE pFirstName LIKE "%'.$searchQuery.'%" OR pLastName LIKE "%'.$searchQuery.'%" OR pFirstName." ".pLastName LIKE "%'.$searchQuery.'%"';

I understand that I can't wright like this: OR pFirstName." ".pLastName LIKE "%'.$searchQuery.'%"';

Can I write it in any other way?
Grateful for any help!
cledus
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Jun 07, 2012 5:20 am

Re: question about mysql_query

Postby ejsexton82 » Thu Jun 07, 2012 10:32 pm

You can use the CONCAT() function:

Code: Select all
$queryPerson = 'SELECT * FROM persons WHERE '
   . sprintf("pFirstName LIKE '%%%s%%' ", mysql_real_escape_string($searchQuery))
   . sprintf("OR pLastName LIKE '%%%s%%' ", mysql_real_escape_string($searchQuery))
   . sprintf("OR CONCAT(pFirstName,' ',pLastName) LIKE '%%%s%%';",
      mysql_real_escape_string($searchQuery));
User avatar
ejsexton82
New php-forum User
New php-forum User
 
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.