SELECT and DATE issues
| From: | Daniel Schmolze | Date: | Thu, 01 Jun 2000 23:01:08 +0000 |
| Subject: | SELECT and DATE issues | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-879@lists.php.net to get a copy of this message | ||
Could anyone tell me why the following code is not working?
(sMon and sYear are hidden inputs)
$theDate = getdate(mktime(0, 0, 0, $sMon, 1, $sYear));
$mon = $theDate["mon"];
$month = $theDate["month"];
$year = $theDate["year"];
$tDate = getdate(mktime(0,0,0,$mon,1,$year));
$firstwday= $tDate["wday"];
// get the last day of the month
$cont = true;
$tDay = 27;
while (($tDay <= 32) && ($cont)) {
$tDate = getdate(mktime(0,0,0,$mon,$tDay,$year));
if ($tDate["mon"] != $mon) {
$lastday = $tDay - 1;
$cont = false;
}
$tDay++;
}
$sd = sprintf("\"%d-%d-00\"", $year, $mon);
$ed = sprintf("\"%d-%d-%d\"", $year, $mon, $lastday);
// connect to the database
$db = mysql_connect("localhost", "*****", "*****");
// select the table
mysql_select_db("calendar", $db);
// do the SELECT, using this month's dates
$result = mysql_query("SELECT * FROM events WHERE date between $sd and $ed", $db);
The problem seems to lie with the SELECT query, since the following
works fine:
$result = mysql_query("SELECT * FROM events WHERE date between (\"2000-06-00\") and
(\"2000-06-31\")", $db);
Anyone know what's going on here?
Thanks.