An easier way would be to use the built-in MySQL functions directly. That way,
you avoid issues with date-format conversions between PHP and MySQL.

Look at: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

You code then becomes:

switch ($type) {
case "today": $sql = "... where field = current_date()"; break;
case "tomorrow": $sql = "... where field = (INTERVAL 1 DAY + current_date())";
break;
case "week": $sql = "... where field = (INTERVAL 1 WEEK + current_date())";
break;
default: die("Don't know what to do?");

HTH,

Yves

------ Original Message ------
Received: Mon, 28 Apr 2008 01:32:31 PM CDT
From: Nasreen Laghari <[EMAIL PROTECTED]>
To: php-db@lists.php.net
Subject: [PHP-DB] Query Criteria

Hi All,
I need help in below coding as it is not working.
What I'm trying to do here, if $type contains "today" value then bring all
record which has today's date, If $type contains "tomorrow" bring all
tomorrow's record. 
Do you think below coding is correct? becuase when I run this query I get
exception but if I place only one $query and outside of if.. else  the same
query runs without errors.
 
 
Thank you for your help
 
Regards
 
$query;

$date = date("d/m/y");

  if($type=="today")
{
  $query = "SELECT * FROM gig where gig_Date= $date";
}
else if($type=="tomorrow")
{
  $tomorrow  = mktime(0, 0, 0, date("m")  , date("d")+1, date("Y"));
  $query = "SELECT * FROM gig where gig_Date= $tomorrow";

}
else if($type=="week")
{
  $week  = mktime(0, 0, 0, date("m")  , date("d")+6, date("Y"));
  $query = "SELECT * FROM gig WHERE g.gig_Date <= ".$date." OR g.gig_Date
>=".$week.";
  
}

$result = mysql_query($query)or die(mysql_error());


  return $result;
  }



     
____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now. 
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to