简体   繁体   中英

getting events from database to calendar page

Database: 数据库 Calendar 1: 日历1 Calendar 2: 日历2 Calendar 3: 日历3

I'm trying to getting both events from the database onto Monday 4th and I'm wondering why I am only getting one event for April and May.

$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\">
      &nbsp;<a href='index.php?day=$day_num-$title-$year'>
      $day_num</a><p/>";

if ($day_num == $record['DAYOFMONTH(start_date)']){     
    echo "&nbsp;<a href=\"#\">".$record['title']. "</a><br/>";      
} else{
    echo "<br />&nbsp;" . "<br/>&nbsp;";
}
echo "</td>";
$day_num++;
$day_count++;

EDIT:

while ($day_num <= $days_in_month) {
echo "<td width=\"42\" valign=\"top\">&nbsp;<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 "&nbsp;<a href=\"#\">".$event['title']. "</a><br/>";

} else{
    echo "<br />&nbsp;" . "<br/>&nbsp;";
}
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;
}

}

Open a blank array:

$arr = array();        
 while ($event = mysql_fetch_assoc($result)) {
        $arr[] = $event;//store all the data in the $arr array
    }

Run a foreach loop to to print the event detail:

foreach($arr as $k=>$v){
    if($v['DATEOFMONTH(start_date)']==$day_num){
      echo '<a href="#">'.$v['title'].'</a><br/>';
    }else{
        echo "<br />&nbsp;" . "<br/>&nbsp;";
    }
  }

Hope this may help. demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM