普通网友 2019-06-05 18:10
浏览 281
已采纳

在for循环中显示一个月中每天的记录数,以显示该月的日期

I have a for loop that displays all the days in a month. I also have a table that has various dates stored in it. I want to be able to query that table to select total count of all records of each date in that month and display it on each date in the results of the for loop.

Don't know how to get it done.

I think the problem is in the query construction but i can't figure out the best way to go about it to achieve the aim.

For example, for day one of month June, i want to see 5 slots. for day two, 10 slots, etc

$ucimslots = "25";
$curyear = date("Y");
$month = $_POST['month'];
$day = date('j');
$daysinmonth = date('t',mktime(0,0,0,$month,1,$curyear));


$query = "SELECT uciID, bookingdate, paymentstatus FROM ucibooking WHERE bookingdate=?";
$stmt = $connQlife->prepare($query);
$stmt->bind_param('s', $day);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($uciID, $bookingdate, $paymentstatus);
$stmt->fetch();
$totalnumrows = $stmt->num_rows;
$stmt->close();


if ($totalnumrows!=0){
    $availableslots = $ucimslots - $totalnumrows;
}else if ($totalnumrows==0){
    $availableslots = $ucimslots;
}


<?Php for($day = 1; $day <= $daysinmonth; $day++){?>            
   <div class="calendarcont">
       <div class="calendarheadercont">
           <div class="calendarday"><?Php echo date("l", mktime(0, 0, 0,$month,$day,$curyear)); ?></div>
           </div>
           <div class="clear_1"></div>
           <div class="calendarsubcont">
               <div class="calendardatecont">
                   <div class="calendarmonth"><?Php echo date("M", mktime(0,0,0, $month,$day,$curyear)); ?></div>
                   <div class="calendardate"><?Php echo date("j", mktime(0,0,0,$month,$day,$curyear)); ?></div>
               </div>
               <div class="calendartextcont">
               <div class="calendartextr"><?Php echo $availableslots; ?></div>
           </div>
       </div>                                           
    </div>
   <?Php } ?> 
  • 写回答

1条回答 默认 最新

  • duan198123 2019-06-06 09:56
    关注

    I solved the issue. So in case anyone else in the future encounters this problem, what i did was i amended the query to the database. The issue was with the query and its call position. It was outside the for loop. So i included it in the for loop like below:

     <?Php for($day = 1; $day <= $daysinmonth; $day++){
        $query = "SELECT uciID, bookingdate, paymentstatus FROM ucibooking WHERE YEAR(bookingdate)=? AND MONTH(bookingdate)=? AND DAY(bookingdate)=?";
        $stmt = $connQlife->prepare($query);
        $stmt->bind_param('sss', $curyear, $month, $day);
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($uciID, $bookingdate, $paymentstatus);
        $stmt->fetch();
        $totalnumrows = $stmt->num_rows;
        $stmt->close();?>
    
           <div class="calendarcont">
               <div class="calendarheadercont">
                   <div class="calendarday"><?Php echo date("l", mktime(0, 0, 0,$month,$day,$curyear)); ?></div>
                   </div>
                   <div class="clear_1"></div>
                   <div class="calendarsubcont">
                       <div class="calendardatecont">
                           <div class="calendarmonth"><?Php echo date("M", mktime(0,0,0, $month,$day,$curyear)); ?></div>
                           <div class="calendardate"><?Php echo date("j", mktime(0,0,0,$month,$day,$curyear)); ?></div>
                       </div>
                       <div class="calendartextcont">
                       <div class="calendartextr"><?Php echo $availableslots; ?></div>
                   </div>
               </div>                                           
            </div>
     <?Php } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料