using mysql "where like" in sql statement

  • tiffix
  • Student
  • Student
  • User avatar
  • Posts: 65
  • Loc: kenya

Post 3+ Months Ago

Kindly anyone let me know how, if possible to use something like:

Code: [ Select ]
select * from members where fullnames like %$q% or number like %$q%


in a MySQL select query.

I know I can use

Code: [ Select ]
select * form members where fullnames like %$q%


Am trying to use the 'where like' statement to query for a row and allow user to enter either fullnames or number as the search term.

Thanks in advance.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9089
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I would think the above would work, its possible you are missing single quotes that may be needed as in:

SQL Code: [ Select ]
SELECT *
FROM members
WHERE fullnames LIKE '%$q%'
OR number LIKE '%$q%'
  1. SELECT *
  2. FROM members
  3. WHERE fullnames LIKE '%$q%'
  4. OR number LIKE '%$q%'


You can also use REGEX to do something similar if you have multiple values to search over:

SQL Code: [ Select ]
SELECT *
FROM members
WHERE fullnames REGEXP 'value1|value2|value3'
OR number REGEXP 'value1|value2|value3'
  1. SELECT *
  2. FROM members
  3. WHERE fullnames REGEXP 'value1|value2|value3'
  4. OR number REGEXP 'value1|value2|value3'

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 60 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.