Quote:
You're right . . . it's VERY wasteful, and I know it. I'm still learning so I draw big and messy, so to speak.
Actually, though, I thought the $counter variable was there to prevent me pulling down the entire set of records, as advised to me in an earlier reply to this post. I'd like to be able to do this more tightly, but more importantly right now, I'd like to get this to WORK.
|
I'm beginning to get the picture here, and I understand that you're just starting out; we all have to start someplace. I really like your comment about 'drawing big and messy' - I've never heard it put quite that way, but that's exactly what it is, isn't it?
Actually, you
do pull down most of the records; if you didn't, how would the if() statement know what to compare against? It has to pull down every record in the table in order to compare against the value in $current_time, then when it hits the 'break' statement, kicks out of the loop and stops. But that doesn't necessarily mean you haven't gone through most of the records in the table prior to that point.
At any rate; I'm quite certain we can eliminate a good 75% of the code you have there with a properly formed SELECT; could you possibly provide a portion of your table schema, i.e. the column names and data types? It's really quite simple to work with dates and times within MySQL, rather than having to convert anything, we can do all the comparisons within the SELECT itself.
Just off the top of my head, without seeing more specifics, I'd say a SELECT statement like this would do what you want:
PHP Code:
// table name declaration
$today = date('l');
// SQL, HEREDOC style
$query =<<< END
SELECT *
FROM {$today}
WHERE NOW() BETWEEN start_time AND end_time
LIMIT 0,7
END;
Please post back with a few more specifics on the table design and perhaps an actual record from the table.