Query Criteria

Query Criteria

am 28.04.2008 20:31:00 von Nasreen Laghari

--0-473964357-1209407460=:40246
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi All,=0AI need help in below coding as it is not working.=0AWhat I'm tryi=
ng to do here, if $type contains "today" value then bring all record which =
has today's date, If $type contains "tomorrow"=A0bring all tomorrow's recor=
d. =0ADo 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=A0 t=
he same query runs without errors.    =0AThank you for your help=0A=
  Regards  =0A$query; $date =3D date("d/m/y"); =A0 if($ty=
pe=="today")=0A{   $query =3D "SELECT * FROM gig where gig_Date=3D =
$date";=0A}=0Aelse if($type=="tomorrow")=0A{   $tomorrow=A0 =3D mkt=
ime(0, 0, 0, date("m")=A0 , date("d")+1, date("Y"));   $query =3D "SELE=
CT * FROM gig where gig_Date=3D $tomorrow"; }=0Aelse if($type=="we=
ek")=0A{   $week=A0 =3D mktime(0, 0, 0, date("m")=A0 , date("d")+6, dat=
e("Y"));   $query =3D "SELECT * FROM gig WHERE g.gig_Date <=3D ".$date.=
" OR g.gig_Date >=3D".$week.";   =0A} $result =3D mysql_query($que=
ry)or die(mysql_error());   return $result;   } =
____________________________________________________________ ___________=
_____________=0ABe a better friend, newshound, and =0Aknow-it-all with Yaho=
o! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=3DAhu06i62sR8HDtDypa=
o8Wcj9tAcJ
--0-473964357-1209407460=:40246--

Re: Query Criteria

am 28.04.2008 21:25:23 von Yves Sucaet

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-functio ns.h=
tml

You code then becomes:

switch ($type) {
case "today": $sql =3D "... where field =3D current_date()"; break;
case "tomorrow": $sql =3D "... where field =3D (INTERVAL 1 DAY + current_=
date())";
break;
case "week": $sql =3D "... where field =3D (INTERVAL 1 WEEK + current_dat=
e())";
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
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 al=
l
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 sa=
me
query runs without errors.
=

=

Thank you for your help
=

Regards
=

$query;

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

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

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

}

$result =3D 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=3DAhu06i62sR8HDtDypao8Wcj9tAcJ




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