|
 |
|
ช่วยดู code ให้ผมทีคับ พอดีผมทำระบบจองบ้านพัก และผมติดตรงสถานะ เลยไม่รู้ว่าจะเขียน code ออกมาเป็นแบบไหน |
|
 |
|
|
 |
 |
|
เอา Code เฉพาะตรงที่มีปัญหามาก็พอครับ 
|
 |
 |
 |
 |
Date :
2013-03-01 05:52:46 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือผมไม่รู้อ่ะคับ ว่าจะเขียนไว้ส่วนไหน น่าจะอันนี้

ส่วนอันนี้เป็น ฟังก์ชั่นที่ผมดึงออกมาแสดงผลที่หน้า เว็บคับ พอดีทำเป็นคนละไฟล์กัน

|
 |
 |
 |
 |
Date :
2013-03-01 10:46:27 |
By :
ice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เก็บข้อมูลไว้ตรงไหน ว่าห้องว่างหรือไม่ว่างครับ (เหมือนผมจะเห็นฟิลด์ชื่อ status ในโค้ดนะครับ ใช่รึเปล่า)
ถ้าใช่ หลังจากกรอกแบบฟอร์มแล้ว เราก็ทำการ update ให้ status ของห้องนั้นไม่ว่างครับ
จากโค้ดที่ให้มา อันแรก ผมเดาว่าคือรายชื่อห้องทั้งหมด ทั้งว่างและไม่ว่าง ไม่เกี่ยวกับส่วนนี้นะครับ
|
 |
 |
 |
 |
Date :
2013-03-01 11:11:46 |
By :
earthchie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช่คับ ตามแบบที่คุณว่า คือผมต้องไปเขียน โค๊ดที่ ฟอม กรอกข้อมูล ใช่รึป่าวคับ


แต่ว่าผมจะเขียนยังไงดีคับ คือผมลองดูโค๊ดจากระทู้เก่าๆ แล้วยังประยุกต์ไม่ได้สักที T_T
|
 |
 |
 |
 |
Date :
2013-03-01 11:27:56 |
By :
ice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลงซํ้าไปอันนึง

|
 |
 |
 |
 |
Date :
2013-03-01 11:29:11 |
By :
ice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอดูโค้ดของฟังก์ชัน create() หน่อยครับ
|
 |
 |
 |
 |
Date :
2013-03-01 12:01:55 |
By :
earthchie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นี่คับ

|
 |
 |
 |
 |
Date :
2013-03-01 12:05:35 |
By :
ice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับ เพิ่ม query สำหรับการอัพเดตสถานะห้องให้กลายเป็นไม่ว่าง ในฟังก์ชัน create นี่แหละครับ
(แนะนำเขียนเป็นฟังก์ชันแยก แล้วเรียกใช้เอา)
เช่น
Code (PHP)
function create(.....){
$con = connectTODB();
$query = .......
mysqli_query($con,$query);
updateRoomStatus($roomID,'not available');
}
function updateRoomStatus($roomID,$status){
$con = connectTODB();
$query = "UPDATE room SET status='".$status."' WHERE room_id = ".$roomID;
return mysqli_query($con,$query);
}
ประมาณนี้ครับ
|
 |
 |
 |
 |
Date :
2013-03-01 12:20:16 |
By :
earthchie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$ roomid นี่ เป็นของ ไพมารี่คีย์ ของตารางหน้าแรกใช่ปะคับ
|
 |
 |
 |
 |
Date :
2013-03-01 12:47:40 |
By :
ice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับ เอาไว้ระบุว่าห้องไหนที่ถูกจองครับ
|
 |
 |
 |
 |
Date :
2013-03-01 13:50:14 |
By :
earthchie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้อ่ะคับ มันขึ้นนี่ เหมือนมัน orderid มันไม่ส่งค่าไปอ่ะคับ

ลองดูโค๊ดคับ
Code (PHP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
</head>
<body>
<?php
include_once 'database/smet_db.php';
if(($result = read())!=null){
?>
<?php
include_once 'database/smet_db.php';
if(isset($_REQUEST['del'])){
delete($_REQUEST['del']);
}else if (isset($_REQUEST['edit'])){
if(($editResult = read($_REQUEST['edit'])) !=null){
$showEdit = true;
while($rowEdit = mysqli_fetch_array($editResult)){
$orderid= $rowEdit['orderid'];
$zone =$rowEdit['zone'];
$camp = $rowEdit['bedroom'];
$bedroom = $rowEdit['lname'];
$bathroom = $rowEdit['bathroom'];
$people = $rowEdit['people'];
$price = $rowEdit['price'];
$facilities= $rowEdit['facilities'];
$status=$rowedit['status'];
}
}
}
?>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<center>
<table border ="1" width="80%">
<tr bgcolor="green">
<th colspan="10" align="center" height="30">ที่พักของอุทยานแห่งชาติ เขาแหลมหญ้า-หมู่เกาะเสม็ด โปรดเลือกที่พักเพื่อทำการจอง</th>
</tr>
<tr bgcolor="green">
<th width="7%" height ="25">โซน</font></th><th align="center"width="20%">ที่พักและบริการ</th><th align ="center">ห้องนอน</th><th align="center">ห้องน้ำ</th>
<th align="center">คน/หลัง</th><th align="center">ราคา/คืน</th><th align="center"width="10">สื่งอำนวยความสะดวก</th>
<th align="center" width="10">สถานะ</th><th align="center" width="10">จอง</th>
<?php
if(isset($showEdit)&&$showEdit)echo"value='$orderid'readonly=readonly'";
?>
<?php
$rowCount = 0;
$rowColour ="";
while ($row =mysqli_fetch_array($result)){
echo"<tr>";
echo"<td align='center'>".$row['zone']."</td>";
echo"<td>".$row['camp']."</td>";
echo"<td align='center'>".$row['bedroom']."</td>";
echo"<td align='center'>".$row['barthroom']."</td>";
echo"<td align='center'>".$row['people']."</td>";
echo"<td align='center'>".$row['price']."</td>";
echo"<td>".$row['facilities']."</td>";
echo"<td align='center'>".$row['status']."</td>";
echo"<td align='center'><a href='customer.php?edit=".$row['orderid']."'>edit</a></td>";
echo"</tr>";
echo"</tr>";
}
echo"<table>";
}
else{
echo "ไม่พบข้อมูล";
}
?>
<?php if(isset($showEdit)&&$showEdit)echo"<input type='hidden' id='editing' name'editing value='true'";?>
<?php if(isset($showEdit)&&$showEdit)echo"<input type='hidden' id='orderid' name'orderid value='$orderid'";?>
<?php
$status="";
if($status==null){
updateRoomStatus($orderid,$zone,$camp,$bedroom,$bathroom,$people,$price,$facilities,$status);
}else{
updateRoomStatus($$orderid,$zone,$camp,$bedroom,$bathroom,$people,$price,$facilities,$status);
}
?>
</table>
<br>
<br>
<br>
<center>
<table border ="1" width="80%">
<tr>
<tr bgcolor="green">
<th colspan="10" align="center" height="30">รายละเอียดแสดงโซนที่พักก่อนทำการจอง (หากจองคนละโซน ที่พักจะอยู่ไกลกัน)</td></tr>
<tr bgcolor="green">
<th width="7%" height ="25"><font class="" color="">โซน</font></th>
<th width="20%"><font class="" color="">กลุ่มที่พัก</font></th>
<th width="50%"><font class="" color="">คำอธิบายเพิ่มเติม</font></th>
</tr>
<tr bgcolor="">
<td align="center" height="25"><font class="" color="">1</font></td>
<td><font class="" color="">แหลมหญ้า 101, 102</font></td>
<td><font class="" color="">บ้านพักเดี่ยว และบ้านพักเดี่ยวแยกเป็นห้อง โซนที่ทำการอุทยานแห่งชาติ (อยู่บนฝั่ง บริเวณเขาแหลมหญ้า)</font></td>
</tr>
<tr bgcolor="">
<td align="center" height="25"><font class="" color="">1</font></td>
<td><font class="" color="">แหลมหญ้า 103-105</font></td>
<td><font class="" color="">บ้านพักเดี่ยว โซนที่ทำการอุทยานแห่งชาติ (อยู่บนฝั่ง บริเวณเขาแหลมหญ้า)</font></td>
</tr>
<tr bgcolor="">
<td align="center" height="25"><font class=""color="">2</font></td>
<td><font class="" color="">แหลมหญ้า 201/1-3</font></td>
<td><font class="" color="">บ้านพักเดี่ยวแยกเป็นห้อง บริเวณหน่วยพิทักษ์อุทยานแห่งชาติ ที่ ญส.2 (อยู่บนเกาะเสม็ด บริเวณแหลมลูกโยน)</font></td>
</tr>
<tr bgcolor="">
<td align="center" height="25"><font class="" color="">3</font></td>
<td><font class="" color="">แหลมหญ้า 931-934</font></td>
<td><font class="" color="">ค่ายเยาวชน (อยู่บนเกาะเสม็ด บริเวณอ่าวพร้าว ไม่ติดชายทะเล)</font></td>
</tr>
<tr bgcolor="">
<td align="center" height="25"><font class="" color="">4</font></td>
<td><font class="" color="#000000">แหลมหญ้า 401-405</font></td>
<td><font class="" color="#000000">บ้านพักเดี่ยว บริเวณหน่วยพิทักษ์อุทยานแห่งชาติ ที่ ญส.3 (อยู่บนเกาะกุฎี ต้องเหมาเรือไปใช้ไฟปั่นเริ่มปั่นไฟ 17.00- 22.00น.)</font></td>
</tr>
</center>
</form>
</body>
</html>
ส่วนนี่หน้าฟังก์ชั่นคับ
Code (PHP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
include_once 'connectdatabase.php';
function create($mint,$fname,$lname,$ssn,$address,$cou,$code_1,$province,$tel,$email){
$con=connectTODB();
$query="insert into customer(mint,fname,lname,ssn,address,cou,code_1,province,tel,email)values
('$mint','$fname','$lname','$ssn','$address','$cou','$code_1','$province','$tel','$email')";
updateRoomStatus($orderid,'not');
mysqli_query($con,$query);
}
function updateRoomStatus($orderid,$status){
$con = connectTODB();
$query = "UPDATE smet SET status='".$status."' WHERE orderid = ".$orderid;
echo"$query";
return mysqli_query($con,$query);
}
?>
</html>
|
 |
 |
 |
 |
Date :
2013-03-01 18:17:25 |
By :
ice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ LAST_INSERT_ID() ครับ
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
include_once 'connectdatabase.php';
function create($mint,$fname,$lname,$ssn,$address,$cou,$code_1,$province,$tel,$email){
$con=connectTODB();
$query="insert into customer(mint,fname,lname,ssn,address,cou,code_1,province,tel,email)values
('$mint','$fname','$lname','$ssn','$address','$cou','$code_1','$province','$tel','$email')";
if(mysqli_query($con,$query)){
$query="select LAST_INSERT_ID() ";
$result=mysqli_query($con,$query) or die(mysql_error()."[$query]");
list($orderID) = mysqli_fetch_row($result);
updateRoomStatus($orderID,'not');
}
}
function updateRoomStatus($orderid,$status){
$con = connectTODB();
$query = "UPDATE smet SET status='".$status."' WHERE orderid = ".$orderid;
echo"$query";
return mysqli_query($con,$query);
}
?>
</html>
|
 |
 |
 |
 |
Date :
2013-03-01 18:39:07 |
By :
ฮาโหลลลล |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คิวรี่ผ่านแล้ว แต่มันยังไม่อัพเดทสถานะลงในฐานข้อมูลอ่ะคับ รวมถึง หน้าเว็บด้วย ผมต้องกำหนดตัวแปรไรรึป่าว
|
 |
 |
 |
 |
Date :
2013-03-01 18:54:44 |
By :
ice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอดูโครงสร้าง table smet หน่อยครับ
จับภาพมาให้ก็ได้ครับ
|
 |
 |
 |
 |
Date :
2013-03-01 19:13:39 |
By :
earthchie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นี่คับ

|
 |
 |
 |
 |
Date :
2013-03-01 19:53:31 |
By :
ice |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|