If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > LIKE or relevant option to get results without changing query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-15-11, 11:16
mavera2 mavera2 is offline
Registered User
 
Join Date: Nov 2011
Posts: 1
LIKE or relevant option to get results without changing query

I have a complex query. I paste some part of it below.

Code:
$query =  "SELECT *  FROM mytable WHERE Day LIKE '%$day%'";
-------------Day
Record1-----1234567
Record2-----67
Record3-----123
Record4-----4
Record5-----345

I set parameter $day to get relevant records.
If i want some particular day, no problem, i set
Code:
$day=2;
But when i want to get all results wtihout looking to day value this query doesn't work.

What should i set to $day variable or change "LIKE" part which provides me to get records,
* when i search for particular day
* when the day is not an important criteria (get all records)

without changing the query for each option?

Thank you.
Reply With Quote
  #2 (permalink)  
Old 11-15-11, 15:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
empty string
Code:
$day='';
then the query resolves to
Code:
SELECT *  FROM mytable WHERE Day LIKE '%%'
that should return all rows

assuming Day is VARCHAR
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Tags
like operator, mysql

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On