本文介绍了在循环中需要帮助以显示来自sql的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我正在制作休假日历...我想比较日期,如果匹配,背景将被更改.我尝试做的是首先获得两个循环,分别是12个月和秒,以获取该月中的天数,并且我使用的是$ num = cal_days_in_month(CAL_GREGORIAN,$ Month,$ cYear)
这将是该月的天数...
然后有一个我的sql查询,它将从数据库中选择日期和其他数据..
现在我遇到的问题是,天数没有增加,它显示的日期像2011-1-1,2011-1-1等,而不是2011-1-1、2011-1-2 ....
请帮助我..这里
<<pre lang="xml">table > <?php for($Month=01;$Month <= 12;) { ?> <tr> <td width="18%" colspan="2"><strong><?php echo $monthNames[$Month-1]; ?></strong></td> <td width="12%" colspan="2"><strong>Division</strong></td> <?php $num = cal_days_in_month(CAL_GREGORIAN, $Month, $cYear); // 31 //$dates = date("$cYear-$Month-1"); $sql ="SELECT leave_date FROM `hs_hr_leave` WHERE employee_id = $emplid "; $res = mysql_query($sql); for($i=1;$i<=$num;$i++) { $dates = date("$cYear-$Month-$i"); echo $dates."<br/>"; while ($row = mysql_fetch_array($res, MYSQL_NUM)) { $time2=date("Y-n-j",strtotime ($row[0])).''<br/>''; foreach($row as $key=>$value) { } //echo "<td bgcolor=''red''>".$dates."--".$time2."</td>"; //echo "<td>".$row[1]."</td><br/>"; //echo "<td>".$row[1]."</td><br/>"; //echo "<td>".$row[2]."</td><br/>"; } //echo "<td width=''26'' height=''20px'' align=''center'' valign=''middle'' >".$i."</td>"; } //echo "<br/>"; $Month++; } ?> </tr> </tabl
e>
解决方案
hii am am making a leave calendar ...i want to compare dates and if the matches the background will be changed .
i am try to do is i got two loops first for 12 months and seconds for numbers of days in that month and i am using $num = cal_days_in_month(CAL_GREGORIAN, $Month, $cYear)
this will give be numbers of days in that month...
then there is a my sql query which will select that dates and other data from database ..
now problem i am have is that numbers of days are not increment it show date like 2011-1-1 ,2011-1-1 and so on instead of 2011-1-1, 2011-1-2....
please help me ..here
<<pre lang="xml">table > <?php for($Month=01;$Month <= 12;) { ?> <tr> <td width="18%" colspan="2"><strong><?php echo $monthNames[$Month-1]; ?></strong></td> <td width="12%" colspan="2"><strong>Division</strong></td> <?php $num = cal_days_in_month(CAL_GREGORIAN, $Month, $cYear); // 31 //$dates = date("$cYear-$Month-1"); $sql ="SELECT leave_date FROM `hs_hr_leave` WHERE employee_id = $emplid "; $res = mysql_query($sql); for($i=1;$i<=$num;$i++) { $dates = date("$cYear-$Month-$i"); echo $dates."<br/>"; while ($row = mysql_fetch_array($res, MYSQL_NUM)) { $time2=date("Y-n-j",strtotime ($row[0])).''<br/>''; foreach($row as $key=>$value) { } //echo "<td bgcolor=''red''>".$dates."--".$time2."</td>"; //echo "<td>".$row[1]."</td><br/>"; //echo "<td>".$row[1]."</td><br/>"; //echo "<td>".$row[2]."</td><br/>"; } //echo "<td width=''26'' height=''20px'' align=''center'' valign=''middle'' >".$i."</td>"; } //echo "<br/>"; $Month++; } ?> </tr> </tabl
e>
解决方案
这篇关于在循环中需要帮助以显示来自sql的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!