我正试图从数据库中获取这两个事件到星期一4号,我想知道为什么我只在四月和五月举办一个活动。
$sql = "SELECT title, contact, contact_email, DAYOFMONTH(start_date)
FROM $caltbl WHERE start_date LIKE '$year-$month%'";
$result = mysql_query($sql)or die(mysql_error());
$row_count = mysql_num_rows($result);
$record = mysql_fetch_array($result);
while ($day_num <= $days_in_month) {
echo "<td width=\"42\" valign=\"top\">
<a href='index.php?day=$day_num-$title-$year'>
$day_num</a><p/>";
if ($day_num == $record['DAYOFMONTH(start_date)']){
echo " <a href=\"#\">".$record['title']. "</a><br/>";
} else{
echo "<br /> " . "<br/> ";
}
echo "</td>";
$day_num++;
$day_count++;
编辑:
while ($day_num <= $days_in_month) {
echo "<td width=\"42\" valign=\"top\"> <a href='index.php?day=$day_num-$title-$year'>$day_num</a><p/>";
if ($day_num == $record['DAYOFMONTH(start_date)']){
while ($event = mysql_fetch_assoc($result)) {
$array[] = $event;
}
print_r($array);
echo " <a href=\"#\">".$event['title']. "</a><br/>";
} else{
echo "<br /> " . "<br/> ";
}
echo "</td>";
$day_num++;
$day_count++;
// Make sure we start a new row each week
if ($day_count > 7) {
echo "</tr><tr>";
$day_count = 1;
}
}
答案 0 :(得分:0)
打开一个空白数组:
$arr = array();
while ($event = mysql_fetch_assoc($result)) {
$arr[] = $event;//store all the data in the $arr array
}
运行foreach循环以打印事件详细信息:
foreach($arr as $k=>$v){
if($v['DATEOFMONTH(start_date)']==$day_num){
echo '<a href="#">'.$v['title'].'</a><br/>';
}else{
echo "<br /> " . "<br/> ";
}
}
希望这可能会有所帮助。 demo