Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011
    Posts
    1

    Unanswered: 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.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •