Quote:
|
What's that <<< END on the end of $query all about? And would LIMIT 0,7 grab the 7 records following the one tested with WHERE NOW() BETWEEN start_time AND end_time??
|
As mentioned in the comment, the END is simply part of the
HEREDOC style; I prefer using HEREDOC when I create an SQL query in my PHP scripts, makes it easier for me to read / manipulate the query instead of having to muck around with quotes and all that.
Yes, the LIMIT clause will return 8 results, starting with the first (counting from zero) in the resultset stipulated in the WHERE clause.
Unfortunately, rather than using timestamps in your table you're converting the values with PHP and inserting those values instead; I see now what you meant in your previous post. You really should consider utilizing timestamp type for these columns. On the subject, I don't quite understand your unique method for timestamp; you take the time in minutes, add that to the product of 60 and the time in hours. So at this moment, it's 11PM, or 23:00 hours, which in your script becomes '1320' (which if you're using this as a timestamp, is more relatable to 1:20PM). Regardless, if you continue to use the same method in your script, should create a unique timestamp that will increment throughout the day.
So taking this into consideration, you should be able to use the same combination of values in the query, e.g.
PHP Code:
// table declaration
$today = date("l");
// unique 'timestamp'
$timestamp = intval(date("i")) + (60 * intval(date("H")));
// SQL
$query = <<< END
SELECT *
FROM {$today}
WHERE {$timestamp} BETWEEN start_time AND end_time
LIMIT 0,7
END;
// run the query, return the resultset
$result = mysql_query($query) OR die(mysql_error());
// run a while loop over the resultset
while( $row = mysql_fetch_array($result, MYSQL_ASSOC))
{
// display the results for each record (simple formatting)
echo $row['id'] ."\t";
// etc
echo $row['start_time'] ."\t";
// etc
echo $row['time_label'] ."\t";
// etc
echo '<br />';
}
Unless I'm mistaken, that should work for you...
If you'd like, I'd be happy to advise further or provide some changes to optimize your table layout.