<table style="border: 1px solid;">
<thead>
<tr>
<td style="border:1px solid;padding:11px;">Time</td>
<td style="border:1px solid;padding:11px;">Book</td>
</tr>
</thead>
<tbody>
<?php
$starttime = $query2['starttime']; // your start time
$endtime = $query2['endtime']; // End time
$duration = '30'; // split by 30 mins
echo "Availability Timing :- "; echo $starttime;echo " to " ;echo $endtime;
echo "<span style='color:red;'>"; echo "<br>Availability Days :- "; echo $query2['days']; echo "</span>";
//echo "<br>Select Date :- "; echo $_POST['date'];
$array_of_time = array ();
$start_time = strtotime ($starttime); //change to strtotime
$end_time = strtotime ($endtime); //change to strtotime
//echo $single_time; <?php echo current($array_of_time); echo " - ";echo next($array_of_time); echo '<br>';
$add_mins = $duration * 60;
while ($start_time <= $end_time) // loop between time
{
$array_of_time[] = date ("h:i a", $start_time);
$start_time += $add_mins; // to check endtime
}
$arr_ctr=count($array_of_time)-1;
foreach ($array_of_time as $key => $single_time) {
if($arr_ctr>$key){
?>
<tr>
<td style="border:1px solid;padding:11px;">
<?php
$query5=mysql_query("select * from doctorbooking where aday='2016-09-29' and demail='".$query2['email']."'");
$query6=mysql_fetch_array($query5);
//echo $query6['atime'];
//var_dump($query6);
if (($array_of_time[$key] . ' - ' . $array_of_time[$key+1])==$query6['atime'])
{
echo $array_of_time[$key] . ' - ' . $array_of_time[$key+1] . '<br /><span style="color:red;background-color:#C0C0C0;">Booked</span>';
} else
{
echo $array_of_time[$key] . ' - ' . $array_of_time[$key+1] . '<br /><span style="color:red;">Available</span>';
}
?>
</td>
<td style="border:1px solid;padding:11px;">
<input type="radio" value="<?php echo $array_of_time[$key].' - '.$array_of_time[$key+1]; ?>" id="A" name="A"></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
问题是我想通过选择特定的邮件ID和日期从数据库中选择atime列。我在数据库中有4个atime值,但它只选择第一个,而不是选择其他.I使用// echo $ query6 ['atime']进行检查;如果已预订,我也想禁用该单选按钮。
答案 0 :(得分:0)
<?php
$array_filter = $array_of_time[$key] . ' - ' . $array_of_time[$key+1];
$is_booked = false;
$query5=mysql_query("select atime from doctorbooking where aday='2016-09-29' and demail='".$query2['email']."'");
//$query6=mysql_fetch_array($query5);
//echo $query6['atime'];
//var_dump($query6);
while( $query6 = mysql_fetch_array($query5) ) {
if ( $array_filter == $query6['atime'] ) {
//it force "booked" as soon as 1 is booked
$is_booked = true;
} else {
// OR uncomment here to force "available" as soon as 1 is availabe
//$is_booked = false;
}
}
if ($is_booked) {
echo $array_filter . '<br /><span style="color:red;background-color:#C0C0C0;">Booked</span>';
} else {
echo $array_filter . '<br /><span style="color:red;">Available</span>';
}
//mysql_data_seek($query5,0);
?>
这是这个问题的解决方案。