[thelist] Re: getting the next row
Mark Groen
markgroen at gmail.com
Sun Mar 6 00:21:26 CST 2005
On Sat, 5 Mar 2005 18:00:35 -0800, Mark Groen <markgroen at gmail.com> wrote:
> I have a list of events for a day and have been able to print an event
> while it's within the start/stop times. Now I want to print the next
> two events, (the sql takes care of the day/order), but stuck on how to
> implement this. Thought now() would be the trick, but missing
> something in the translation. code:
> this prints the info from the same row as "now playing" instead of the
> next row as I expected, what am I missing?
Figured it out with some help from a local php'er, needed to add the
list function so there was an valid array to go next() to, code below
if any of it helps someone else:
<code>
function dttm2unixtime($dttm2timestamp_in){
// returns unixtime stamp for a given date time string that comes from DB
$date_time = explode(" ", $dttm2timestamp_in);
$date = explode("-",$date_time[0]);
$time = explode(":",$date_time[1]);
unset($date_time);
list($year, $month, $day)=$date;
list($hour,$minute,$second)=$time;
return mktime(intval($hour), intval($minute), intval($second),
intval($month), intval($day), intval($year));
}
$query = "SELECT id,title,dj,show_day,show_start,show_end,show_echo
FROM schedule
WHERE show_day = '$myDay'
ORDER BY show_start ";
$mysql_result = mysql_query($query, $mysql_link);
$showList = $mysql_result;
$i = 0; //initialize the title count
$nowOn = 0;
while($row = mysql_fetch_array($showList))
{ $i++; $nowOn++;
$id = $row[0];
$title = $row[1];
$dj = $row[2];
$show_day = $row[3];
$show_start = $row[4];
$show_end = $row[5];
$show_echo = $row[6];
$nextStart = dttm2unixtime("2004-01-31 $show_start"); //2004-11-28 10:20:00
$nextEnd = dttm2unixtime("2004-01-31 $show_end");
$theTime = dttm2unixtime("2004-01-31 $serverTime");
//$hourStart = explode(":", $show_start);
//$hourEnd = explode(":", $show_end);
$num_rows = mysql_num_rows($showList);
$a = array_fill(1, $num_rows, 'foo');
echo "<br>$i";
print(" :: $theTime - $nextStart | $title <b>");
include("timeyes.php");
print("</b>| $nextEnd - $theTime<br>");
if(( ($theTime >= $nextStart)&&($theTime <= $nextEnd) )) //were inside
the shows' hour(s) all is good
{
print("<h1>now playing</h1>\n<strong>");
include("timeyes.php");
print("</strong><br>$title<br>");
$nowTrue = "1";
//the nowTrue = 1 loop start
if($nowTrue = "1")
{ if( list($id, $title, $dj, $show_day, $show_start, $show_end,
$show_echo) = mysql_fetch_array($showList) )
if(( (next($a))&&($title != '') ))
{ print("<h1>next</h1>\n<strong>");
include("timeyes.php");
print("</strong><br>$title<br>");
}
}
{ if( list($id, $title, $dj, $show_day, $show_start, $show_end,
$show_echo) = mysql_fetch_array($showList) )
if(( (next($a))&&($title != '') ))
{ print("<h1>after that</h1>\n<strong>");
include("timeyes.php");
print("</strong><br>$title<br>");
}
}
}else //the next show is sometime after this hour
{ if($nextStart > $theTime)
{ $nowTrue = "noShow"; }
}
}
//etc.
</code>
cheers,
Mark
MG Web Services
www.mgwebservices.ca
Your Canadian West Coast web site development and hosting solution.
More information about the thelist
mailing list