|
 |
|
****ขอคำแนะนำเรื่อง การดึงค่าที่เก็บใน array มาโชว์อีกหน้านึงในช่อง textfield และเก็บข้อมูลลงฐานข้อมูล**** |
|
 |
|
|
 |
 |
|
ได้ทำหน้าตรวจสอบสถานะการจอง ว่า 'ว่าง' กับ 'จองแล้ว' พอกด ว่าง จะไปหน้าจอง ซึ่งในหน้าจองจะดึง ค่า เวลา / สนาม / วันที่ ที่เรากดไปมาโชว์ใน textfield แล้วเก็บค่าลง ตาราง court_booking
แต่ทีนี้คือจะดึงค่า เวลา / สนาม / วันที่ มายังไงคะ


ซึ่งได้ insert ข้อมูล เวลา / สนาม / วันที่ ไว้แล้วใน Table: court_booking

show-booking.php คือหน้าตารางสถานะการจอง
show-booking.php
<?php
include("config/config.inc.php");
mysql_select_db($db);
$arrTime = array('10.00-11.00','11.00-12.00','12.00-13.00','13.00-14.00','14.00-15.00','15.00-16.00','16.00-17.00','17.00-18.00','18.00-19.00','19.00-20.00');
$arrCourt = array(1,2,3,4,5);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ตารางสถานะการจอง</title>
</head>
<body>
<p align="center">ตารางการจองวันที่ : <?php echo $_POST['ckDate']; ?></p>
<?php
$strTable = '<table border="1" width="950" align="center"><tr><td>สนาม/เวลา</td>';
foreach($arrTime as $time){ //สร้างหัวตาราง
$strTable.='<td>'.$time.'</td>';
}
$strTable.='</tr>';
foreach($arrCourt as $courtNum){
$strTable.='<tr><td align="center">'.$courtNum.'</td>';
$sql="Select*From court_booking Where court_num={$courtNum} and court_date_booking='{$_POST['ckDate']}' Order by court_time_booking ASC";
$rs= mysql_query($sql) or die(mysql_error());
$run=0;
foreach($arrTime as $time){
if(mysql_num_rows($rs)>$run && $time == mysql_result($rs,$run,2)){ //ถ้ามีการจอง
$strTable.='<td align="center" bgcolor="#FF000">จองแล้ว</td>';
$run++;
}else{
$strTable.='<td align="center" bgcolor="#00FF00"><a href="court_reserve.php">ว่าง</a></td>';
}
} //End Foreach
$strTable.='</tr>';
}
echo $strTable,'</table>';
?>
</body>
</html>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2014-02-02 14:31:32 |
By :
sama |
View :
1899 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองใส่เป็นแบบนี้ แต่ว่าค่ามันออกมาเป็น < ตัวนี้แทน
แต่ถ้าเปลี่ยนจาก <?php echo "$arrTime[0]"; ?> เป็น <?php echo "$arrTime[1]"; ?> ค่าจะออกเป็น ? แทน
ทำไมมันไม่ออกเป็น 10.00-11.00 คะ
Code (PHP)ส่ง
$strTable.='<td align="center" bgcolor="#00FF00"><a href="court_reserve.php?arrTime=<?echo $arrTime?>&arrCourt=<? echo $arrCourt?>">
Code (PHP)ตอนรับ
<?php
$arrTime = $_GET['arrTime'];
$arrCourt = $_GET['arrCourt'];
?>
<input type="text" name="court_time" id="textfield4" value="<?php echo "$arrTime[0]"; ?>" />
|
 |
 |
 |
 |
Date :
2014-02-04 21:20:02 |
By :
sama |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแบบนี้ดูนะครับ
Code (PHP)
<?php
include("config/config.inc.php");
mysql_select_db($db);
$arrTime = array('10.00-11.00','11.00-12.00','12.00-13.00','13.00-14.00','14.00-15.00','15.00-16.00','16.00-17.00','17.00-18.00','18.00-19.00','19.00-20.00');
$arrCourt = array(1,2,3,4,5);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ตารางสถานะการจอง</title>
</head>
<body>
<p align="center">ตารางการจองวันที่ : <?php echo $_POST['ckDate']; ?></p>
<?php
$strTable = '<table border="1" width="950" align="center"><tr><td>สนาม/เวลา</td>';
foreach($arrTime as $time){ //สร้างหัวตาราง
$strTable.='<td>'.$time.'</td>';
}
$strTable.='</tr>';
foreach($arrCourt as $courtNum){
$strTable.='<tr><td align="center">'.$courtNum.'</td>';
$sql="Select*From court_booking Where court_num={$courtNum} and court_date_booking='{$_POST['ckDate']}' Order by court_time_booking ASC";
$rs= mysql_query($sql) or die(mysql_error());
$run=0;
foreach($arrTime as $time){
if(mysql_num_rows($rs)>$run && $time == mysql_result($rs,$run,2)){ //ถ้ามีการจอง
$strTable.='<td align="center" bgcolor="#FF000">จองแล้ว</td>';
$run++;
}else{
$strTable.='<td align="center" bgcolor="#00FF00"><a href="court_reserve.php?arrTime='.arrTime[$run].'&arrCourt='.$arrCourt[$courtNum].'">ว่าง</a></td>'; //ส่่งค่า arrTime กับ arrCourt
$run++;
}
} //End Foreach
$strTable.='</tr>';
}
echo $strTable,'</table>';
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2014-02-04 22:08:25 |
By :
Gust |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|