Forum Moderators: coopster
$query_schedule = "SELECT gameid, date, DATE_FORMAT(schedule.date, '%a, %b %e') AS formatdate, clock, arena, homeid, visitorid, home.teamname AS home, visitor.teamname AS visitor
FROM schedule, teams
INNER JOIN teams AS home ON (schedule.homeid = home.teamid) INNER JOIN teams AS visitor ON (schedule.visitorid = visitor.teamid)
WHERE schedule.season = 2006
GROUP BY gameid
ORDER BY date ASC";
$schedule = mysql_query($query_schedule, $connect) or die(mysql_error());echo "<table>";
$count=0;
while ($row_schedule = mysql_fetch_assoc($schedule)){
$count++;
if(($count % 2) == 1){
$background = "";
} else {
$background = "#EEEEEE";
}
echo "<tr bgcolor=\"".$background."\">
<td>".$row_schedule['formatdate']."</td>
<td>".$row_schedule['clock']."</td>
<td>".$row_schedule['arena']."</td>
<td>".$row_schedule['home']."</td>
<td>".$row_schedule['visitor']."</td>
</tr>
<tr>
<td bgcolor=\"#000000\" height=\"1\" colspan=\"10\"></td>
</tr>";
}
echo "</table>";
What I would like is to have the date only show up once like this:
+------------+------+---+--------+--------+
¦Tue, Apr 18 ¦ 7:30 ¦ A ¦ Team 1 ¦ Team 2 ¦
+------------+------+---+--------+--------+
¦............¦ 8:50 ¦ A ¦ Team 3 ¦ Team 4 ¦
+------------+------+---+--------+--------+
¦............¦ 10:10¦ A ¦ Team 5 ¦ Team 6 ¦
+------------+------+---+--------+--------+
¦Thu, Apr 20 ¦ 7:30 ¦ A ¦ Team 7 ¦ Team 8 ¦
+------------+------+---+--------+--------+
¦............¦ 8:50 ¦ A ¦ Team 1 ¦ Team 3 ¦
+------------+------+---+--------+--------+
¦............¦ 10:10¦ A ¦ Team 2 ¦ Team 4 ¦
+------------+------+---+--------+--------+
I just can't seem to get it to work properly. Can anyone help?
This should do what you want. Basically, keep track of the last date, and display it when a new date appears.
echo "<table>";
$count=0;
$date='';
while ($row_schedule = mysql_fetch_assoc($schedule)){
$count++;
if(($count % 2) == 1){
$background = "";
} else {
$background = "#EEEEEE";
}
if($date!=$row_schedule['formatdate']) {
$date=$row_schedule['formatdate'];
$display_date=$date;
} else {
$display_date=' ';
}
echo "<tr bgcolor=\"".$background."\">
<td>".$display_date."</td>
<td>".$row_schedule['clock']."</td>
<td>".$row_schedule['arena']."</td>
<td>".$row_schedule['home']."</td>
<td>".$row_schedule['visitor']."</td>
</tr>
<tr>
<td bgcolor=\"#000000\" height=\"1\" colspan=\"10\"></td>
</tr>";
}
echo "</table>";
Chad
I know it works because the condensed version you gave me works. But when I put everything in that I need, the date doesn't appear ($display_date= )
here is the code:
<?php
echo "<table width=\"625\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" class=\"stats\">";
$count=0;
$date='';
while ($row_schedule = mysql_fetch_assoc($schedule)){
$count++;
if(($count % 2) == 1){
$background = "";
} else {
$background = "#EEEEEE";
}
if(str_replace(array_keys($myArray), array_values($myArray), $row_schedule['gameid']) == "[boxscore]")
$boxlink = "[boxscore]";
else
$boxlink = "";
if($date!=$row_schedule['formatdate']) {
$date=$row_schedule['formatdate'];
$display_date=$date;
} else {
$display_date=' ';
}
echo "<tr bgcolor=\"".$background."\">
<td width=\"13%\">".$display_date."</td>
<td width=\"6%\">".$row_schedule['clock']."</td>
<td width=\"7%\">".$row_schedule['arena']."</td>
<td width=\"15%\"><a href=\"teamschedule.php?team=".$row_schedule['homeid']."&season=".$year."&time=".$time."\">".$row_schedule['home']."</a></td>
<td width=\"4%\">".$row_schedule['homegoals']."</td>
<td width=\"15%\"><a href=\"teamschedule.php?team=".$row_schedule['visitorid']."&season=".$year."&time=".$time."\">".$row_schedule['visitor']."</a></td>
<td width=\"4%\">".$row_schedule['visitorgoals']."</td>
<td width=\"5%\">".$row_schedule['ot']."</td>
<td width=\"9%\"><font size=\"1\"><a href=\"boxscore.php?gameid=".$row_schedule['gameid']."\">".$boxlink."</a></font></td>
<td width=\"22%\"><font size=\"1\">".$row_schedule['notes']."</font></td>
</tr>
<tr>
<td bgcolor=\"#000000\" height=\"1\" colspan=\"10\"></td>
</tr>";
}
echo "</table>";
?>