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.
As I mentioned in an earlier reply, I only need to test ONE of the records to meet the IF requirement, which is related to the server time. I have 24 events to display, and they are in order on the server but they last for different lengths of time, so I need to know not only the start but the end time of each in order to match it to the current server time and to display the next seven events after it, depending on what time someone is looking at my page.
Since I couldn't figure out how to add and subtract with timestamps, I converted them to integers as you can see, and put the start and end times as integers in my mySQL database.
Since you asked, here's more of my code, with protected information covered by All CAPS.
PHP Code:
<?php
$conn = mysql_connect(CONNECTSTRING) or die ("Problem connecting to the database" . mysql_error() );
$today = date("l");
$current_minutes = intval(date("i",time())) + (60 * intval(date("H",time())));
$counter = 0;
$now_counting = false;
$rs = mysql_select_db(RESULTCONNECTSTRING);
$query = "SELECT start_time,end_time,time_label,name,image,info_link FROM {$today}";
$rs = mysql_query($query,$conn);
while($row=mysql_fetch_array($rs)){
if ($current_time >= $row[start_time] && $current_time < $row[end_time]) {
$now_counting = true;
}
if($now_counting == true) {
$time_label[$counter] = $row[time_label];
$name[$counter] = $row[name];
$info_link[$counter] = $row[info_link];
$image[$counter] = $row[image];
$counter++;
}
if($counter > 7)
break;
}