I am displaying an events schedule with PHP querying my MySQL database. I need to be able to get the WHAT'S ON NOW to display the current event. I have been doing it this way:
// Second part of query for next day events starting at midnight to follow last current day's event
$query = mysql_query("select * from TABLE where (DATECOL = curdate() and STARTCOL >= curtime()) or (DATECOL = (curdate()+1) and STARTCOL >= curtime()) order by date,start limit 1") or die (mysql_error());
$num_results = mysql_num_rows($query);
if (!$num_results)
{
echo "Schedule to be updated soon.";
}
for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_array($query);
$id = $row['EVENTID'];
$id2 = $id-1;
$query = mysql_query("select * from TABLE where id='$id2'");
... And so on...
The problem is that by relying on auto increment id numbers, I can never insert an event between two other events.
Does anyone have a better way of doing this?
// Second part of query for next day events starting at midnight to follow last current day's event
$query = mysql_query("select * from TABLE where (DATECOL = curdate() and STARTCOL >= curtime()) or (DATECOL = (curdate()+1) and STARTCOL >= curtime()) order by date,start limit 1") or die (mysql_error());
$num_results = mysql_num_rows($query);
if (!$num_results)
{
echo "Schedule to be updated soon.";
}
for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_array($query);
$id = $row['EVENTID'];
$id2 = $id-1;
$query = mysql_query("select * from TABLE where id='$id2'");
... And so on...
The problem is that by relying on auto increment id numbers, I can never insert an event between two other events.
Does anyone have a better way of doing this?