下午好,
我遇到了一个问题,我不知道如何修复。
我正在使用php和mysql制作议程,但我认为我的方法是错误的。如果一天有1个约会,但如果有2个已被打破,它现在可以正常工作。
我的代码:
include('../dbc.php');
$dag = $_GET['dag'];
$maand = $_GET['maand'];
$jaar = $_GET['jaar'];
$datum = $jaar."-".$maand."-".$dag;
$datavergader = mysqli_fetch_assoc(mysqli_query($dbc,"SELECT * FROM `tbl_reservatie` WHERE op = '".$datum."' AND ruimte = 'vergader';"));
在这里,我正在制作一张每小时一半的表格,如果我有约会,我会更改颜色以改变颜色。
<table cellspacing="0" style="width:100%">
<tr>
<th>8:00</th>
<td <?php if($datavergader['van'] == "800"){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>8:30</th>
<td <?php if(($datavergader['van'] <= "830") && ($datavergader['tot'] >= "830" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>9:00</th>
<td <?php if(($datavergader['van'] <= "900") && ($datavergader['tot'] >= "900" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>9:30</th>
<td <?php if(($datavergader['van'] <= "930") && ($datavergader['tot'] >= "930" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>10:00</th>
<td <?php if(($datavergader['van'] <= "1000") && ($datavergader['tot'] >= "1000" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>10:30</th>
<td <?php if(($datavergader['van'] <= "1030") && ($datavergader['tot'] >= "1030" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>11:30</th>
<td <?php if(($datavergader['van'] <= "1130") && ($datavergader['tot'] >= "1130" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>12:00</th>
<td <?php if(($datavergader['van'] <= "1200") && ($datavergader['tot'] >= "1200" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>12:30</th>
<td <?php if(($datavergader['van'] <= "1230") && ($datavergader['tot'] >= "1230" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>13:00</th>
<td <?php if(($datavergader['van'] <= "1300") && ($datavergader['tot'] >= "1300" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>13:30</th>
<td <?php if(($datavergader['van'] <= "1330") && ($datavergader['tot'] >= "1330" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>14:00</th>
<td <?php if(($datavergader['van'] <= "1400") && ($datavergader['tot'] >= "1400" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>14:30</th>
<td <?php if(($datavergader['van'] <= "1430") && ($datavergader['tot'] >= "1430" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>15:00</th>
<td <?php if(($datavergader['van'] <= "1500") && ($datavergader['tot'] >= "1500" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>15:30</th>
<td <?php if(($datavergader['van'] <= "1530") && ($datavergader['tot'] >= "1530" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>16:00</th>
<td <?php if(($datavergader['van'] <= "1600") && ($datavergader['tot'] >= "1600" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>16:30</th>
<td <?php if(($datavergader['van'] <= "1630") && ($datavergader['tot'] >= "1630" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>17:00</th>
<td <?php if(($datavergader['van'] <= "1700") && ($datavergader['tot'] >= "1700" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>17:30</th>
<td <?php if(($datavergader['van'] <= "1730") && ($datavergader['tot'] >= "1730" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>18:00</th>
<td <?php if(($datavergader['van'] <= "1800") && ($datavergader['tot'] >= "1800" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>18:30</th>
<td <?php if(($datavergader['van'] <= "1830") && ($datavergader['tot'] >= "1830" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>19:00</th>
<td <?php if(($datavergader['van'] <= "1900") && ($datavergader['tot'] >= "1900" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>19:30</th>
<td <?php if(($datavergader['van'] <= "1930") && ($datavergader['tot'] >= "1930" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>20:00</th>
<td <?php if(($datavergader['van'] <= "2000") && ($datavergader['tot'] >= "2000" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>20:30</th>
<td <?php if(($datavergader['van'] <= "2030") && ($datavergader['tot'] >= "2030" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
<tr>
<th>21:00</th>
<td <?php if(($datavergader['van'] <= "2100") && ($datavergader['tot'] >= "2100" )){echo 'class="bezet"';}else{ echo "class='beschikbaar'";} ?> ></td>
</tr>
</table>
我知道为什么它没有正确回显其他约会,因为它只能在datavergader中存储一条记录。但我怎么能解决这个问题?
答案 0 :(得分:0)
尝试使用while()
while ($datavergader = mysqli_fetch_assoc(mysqli_query($dbc,"SELECT * FROM `tbl_reservatie` WHERE op = '".$datum."' AND ruimte = 'vergader';"))) {
// you table-rows to display data
}
答案 1 :(得分:0)
如果您的代码从$ _GET这样的URL获取数据,则需要在执行查询之前提供任何规则,并且优先准备&#34; stmt&#34;之后做一个cicle结果数组不是空的例子:
if(mysqli_num_rows($my_stmt_query)>0)
{
while($reult=mysqli_fetch_array($my_stmt_query))
{
echo '<tr><td ....';
if($result['my_var']==$someData) { echo ' class="mystyle" ';}
elseif($result['my_var']<$someData2) { echo ' class="mystyle2" ';}
elseif($result['my_var']<$someData3) { echo ' class="mystyle3" ';}
echo '>'.$result['my_row_data'].'</td></tr>';
}
}
答案 2 :(得分:0)
这里有两个问题:
mysqli_fetch_assoc
获取结果集中当前光标位置的行,不整个结果集!每次调用mysqli_fetch_assoc都会将光标进一步移动一行。当游标到达结尾时(不再需要获取行,或者结果中没有任何行),mysqli_fetch_assoc
将返回false。处理这个问题的一种常见方法是:
$result = mysqli_query($dbc,"SELECT * FROM `tbl_reservatie` WHERE op = '".$datum."' AND ruimte = 'vergader';");
while ($datavergader = mysqli_fetch_assoc($result)) {
// do stuff with row data
}