我遇到一些事件时间表的麻烦。我试图显示所述事件的所有事件,但它只显示一个。我正在使用其他人编码的小cms。我只是想修复事件页面。你会给予任何帮助,我将不胜感激。
以下是代码:
<?php
for( $i = 1; $i <= 7; $i++ ) {
$query = $db->query( "SELECT * FROM events WHERE day = '{$i}'" );
$num = $db->num( $query );
$events = array();
$day = strtotime( "november {$i} 2010" );
$day = date( "l", $day );
while( $array = $db->assoc( $query ) ) {
$time = strtotime( "{$time} on november {$i} 2010" );
$events[$time] = $array['id'];
}
?>
<div class="wrapper">
<div class="title">
<?php
echo $day;
?>
</div>
<?php
if( $num != 0 ) {
?>
<table width="100%" cellpadding="3" cellspacing="1">
<tr style="background: #e9e9e9; font-weight: bold;">
<td width="40%">
Event Name
</td>
<td width="25%">
Host
</td>
<td width="20%">
Hotel
</td>
<td width="15%">
Time
</td>
</tr>
<?php
foreach( $events as $key => $value ) {
$query2 = $db->query( "SELECT * FROM events WHERE id = '{$value}'" );
$array2 = $db->assoc( $query2 );
?>
<tr style="background: #f3f3f3;">
<td width="40%">
<?php
echo $array2['name'];
?>
</td>
<td width="25%">
<?php
echo $array2['host'];
?>
</td>
<td width="20%">
<?php
echo $array2['hotel'];
?>
</td>
<td width="15%">
<?php
echo $array2['time'];
?>
</td>
</tr>
<?php
}
?>
</table>
<?php
} else {
echo "<center>";
echo "There are no events for today!";
echo "</center>";
}
?>
</div>
<?php
}
?>
答案 0 :(得分:0)
您在每个循环中覆盖了$day
变量,因此只会显示最后一个变量。 $events
数组