foreach ($arrTime as $time){
$strTable.='<tr><td><center>'.$time.'</center></td>';
$sql = "select * from booking left join field on booking.field_id=field.field_id where field_name ='{$f_name[field_id]}' and booking_user='2018-06-29' order by booking_time ASC";
$res = mysql_query($sql) or die (mysql_error());
$run=0;
foreach ($arrField as $f_name){
if ($f_name['field_name'] && $time['booking_time'] == mysql_result($res,$run,'booking_time')){//ตรงนี้ที่มีปัญหา
$strTable.='<td bgcolor="#FF0000"><center>จองแล้ว</center></td>';
$run++;
}else{
$strTable.='<td bgcolor="#00CC00"><center>ว่าง</center></td>';
}
}//end forach
$strTable.='</tr>';
}
echo $strTable,'</table>';
$sql = "select * from booking left join field on booking.field_id=field.field_id where field_name ='{$f_name[field_id]}' and booking_user='2018-06-29' order by booking_time ASC";
$res = mysql_query($sql) or die (mysql_error());
$run=0;
ควรจะเขียนเป็น function แล้ว ให้มัน return ค่าที่เราต้องการออกมาเลย
ตัวอย่าง
Code (PHP)
function hasBooking ($date, field_id)
{
$sql = "select * from booking left join field on booking.field_id=field.field_id where field_name =$field_id and booking_user=$date order by booking_time ASC";
$res = mysql_query($sql) or die (mysql_error());
$run=0;
return mysql_result($res,$run,'booking_time');
}