|
 |
|
การ sum ตาม id ที่ได้ตามเงื่อนไขครับดูให้หน่อยครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?
include "Connections/conn_search.php";
mysql_select_db($newDB, $conn);
$sql = "SELECT book_id FROM booking where status='1' or status='2' and check_in <= $checkout and check_out >= $checkin order by book_id asc";
//echo $sql;
$result=mysql_db_query($newDB,$sql);
//$N = mysql_num_rows($result); //$N=นับจำนวนแถวที่ได้ตามเงื่อนไข $sql
$book_id ="";
while ($row1=mysql_fetch_array($result)){
$book_id .=$row1['book_id'].",";
}
if(preg_match('/,$/',$book_id)){ // ตรวจสอบตัวสุดท้ายเป็น ,
$book_id= preg_replace('/,$/','',$book_id); // ลบ , ตัวสุดท้ายออก
}
$book_id;//เงื่อนไขที่ได้ยกตัวอย่างเช่น(00002,00004,00005)แล้วต้องการนำ book_id ที่ได้นี่ไป sum amount(จำนวน) ออกมานะครับต้องเขียนยังไงครับ
$sql = "select roomtype_id sum(amount from bookingdetail where book_id in('$sql=$sql+$book_id+'/*ตรงนี้คือต้องการให้นำ book_id ที่ได้จากข้างบนมาใส่ในนี้นะครับ ต้องเขียนยังไงครับ*/)) group by roomtype_id";
$result=mysql_db_query($newDB,$sql);
echo "<br>";
echo "จำนวนห้องพักทั้งหมด=$sum";
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-11-13 05:17:59 |
By :
giroo |
View :
1582 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 04
|