
April 1st, 2004, 12:17 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
comparing dates
I am trying to write a php page that displays events that are entered by a user. One of the fields for these entries is a date field that the user enters in a YYYY/MM/DD format. When I read the datebase, which is a mysql db, I'm trying to check that the date of the event has not passed. If it has already passed i'm trying to delete it from my database altogether. I'm a little lost on the date comparison as i've managed to do everything from deleting all the records in my DB to deleting none of them. Any help on this code would be a great help. Thanks. This is the code from my display page that I have so far.
PHP Code:
<?php //open connection
$conn = mysql_connect("localhost", "root", "irmdog18");
//select db
mysql_select_db("samplerestaurant_com", $conn);
//create sql
$sql = "select * from event order by event_date";
//execute sql
$result = mysql_query($sql, $conn) or die(mysql_error());
$curdate = time();
//go through each row and display data
while ($newarray = mysql_fetch_array($result)) {
$id = $newarray['id']; $event_title = $newarray['event_title']; $event_date = $newarray['event_date']; $event_listing = $newarray['event_listing']; $event_poster = $newarray['event_poster']; $event_email = $newarray['event_email']; if ($curdate< $event_date) {
$sqlz = "delete from event where event_date = '$event_date'";
//execute sql
$resultz = mysql_query($sqlz, $conn) or die(mysql_error());
}
else
{
echo " <table> <tr> <td NOWRAP width ='200'> <strong><font color ='red'>Event: </font></strong>$event_title<br> <strong><font color ='blue'>Event Date:</font></strong>$event_date<br> <strong><font color ='red'>Event Contact:</font></strong>$event_poster at $event_email<br> </td> <td> </td> <td NOWRAP valign ='top'> <strong><font color ='blue'>Event Description:</font></strong> </td> <td width ='1000000'valign ='top'> $event_listing </td> </tr> </table>
<HR>
";
}
} ?>
|