ช่วยแก้ Code ให้หน่อยครับ PHP

เริ่มโดย deknakhon, 23 พฤษภาคม 2012, 11:17:05

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

deknakhon

ต้องการแสดง สถานะการจอง
เช่นถ้ามีในฐานข้อมูล ให้ แสดง B  ถ้าไม่มีให้แสดง A



<?

//Start Show Booking Detail

function days_in_month($month, $year)
{
// calculate number of days in a month
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
}
$countdate=0;
$countdate=days_in_month($chkmonth ,$chkyear);

if($num_rows>0){//ถ้ามีก็ให้แสดงผลตารางข้อมูล

?>
<table width="100%" border="0"  >
  <tr bgcolor="#FFFFFF">
    <td align="center" width="60"><strong>ห้องพัก</strong></td>
<?php
for($mdays=1;$mdays <=$countdate;$mdays++)
{

?>

    <td align="center"><strong><?=$mdays//แสดงผลหัวคอลัมน์?></strong></td>
<?
}
?>
  </tr>
  <?
  while($ListValue = mysql_fetch_assoc($rsValue)){//วนลูปแสดงผลข้อมูลมิติที่ 1 ตามแนวตั้ง /แถว
  ?>
  <tr bgcolor="#FFFFFF">
    <td align="left" width="60">&nbsp;<?=$ListValue['ROOMNO']//แสดงผลชื่อพื้นที่?></td>
<?
for($mdays=1;$mdays <=$countdate;$mdays++) {
$sql = "SELECT  ARRIVE, DEPART  FROM tb_roomassigns  where  ROOMNO='{$ListValue['ROOMNO']}'
AND  DAY(ARRIVE) ='$mdays'
AND MONTH(ARRIVE)='$chkmonth' 
AND  YEAR(ARRIVE)='$chkyear'  ";//วนลูปหาค่าในแต่ละเชลล์ของตารางตามค่าในคีย์หลักของแถว และ คอลัมน์
$rsColValue = mysql_query($sql) or die("Select error : ".mysql_error());
$nrows=mysql_num_rows($rsColValue);
$ColValue = mysql_fetch_assoc($rsColValue);
//แน่ใจว่าในแต่ละเชลล์มีค่าเดียว จึงไม่ต้องวนลูป ทำ mysql_fetch_assoc เพราะถึงแม้วนลูปค่าที่ได้ก็จะมีแค่ค่าเดียวเหมือนกัน

    // show Booking Status

// Start date
$begin_date = $ColValue['ARRIVE'];
// End date
$end_date = $ColValue['DEPART'];
   
while (strtotime($begin_date) <= strtotime($end_date)) {


if($begin_date=='') {

echo "<td align='center' bgcolor='#f0f0f0'>A</td>";

} else {
echo "<td align='center' bgcolor='blue'>B</td>";



}

$begin_date = date ("Y-m-d", strtotime("+1 day", strtotime($begin_date)));


}
   
// End Show Booking Status


}//end for

}//end while
mysql_free_result($rsColValue); //คืนค่าเมื่อไม่ได้ใช้แล้ว

?>


</tr>
</table>



 




<?

}
else{
echo "<p align=\"center\"><strong>ไม่มีข้อมูล</strong></p>";
}
?>



[Direct=http://upic.me/show/35953747][/Direct]
หรือมีวิธีการที่ดีกว่านี้โปรด ชีแนะด้วยครับ
รับพัฒนาโปรแกรม PHP Mysql
รับออกแบบระบบโปรแกรม
รับวางระบบเครือข่ายคอมพิวเตอร์

goodwide

 :wanwan003:
ขอบคุณครับ
สำหรับ ไอเดีย... คิดไม่ออกนานล่ะ.. :'(

LoveForever

อ้างถึงจาก: goodwide ใน 23 พฤษภาคม 2012, 11:21:02
:wanwan003:
ขอบคุณครับ
สำหรับ ไอเดีย... คิดไม่ออกนานล่ะ.. :'(

:wanwan011: :wanwan011:

ตามนี้ครับ
Fighting

deknakhon

อ้างถึงจาก: goodwide ใน 23 พฤษภาคม 2012, 11:21:02
:wanwan003:
ขอบคุณครับ
สำหรับ ไอเดีย... คิดไม่ออกนานล่ะ.. :'(

ทำได้แล้ว  ช่วยแก้ Code ผมให้ด้วยนะครับ
ขอบคุณลวงหน้าคับ
รับพัฒนาโปรแกรม PHP Mysql
รับออกแบบระบบโปรแกรม
รับวางระบบเครือข่ายคอมพิวเตอร์

codingfi

อัลกอริทึม เยี่ยมมากครับ

return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);

:wanwan013:
บริการจองตั๋วรถทัวร์ผ่านระบบออนไลน์ สายเหนือ สายใต้ สายอีสาน ทุกเส้นทาง !!!!
[direct=https://www.xn--72cb4bef4ec2ad7c5be74ava.net]จองตั๋วรถทัวร์ออนไลน์[/direct] |[direct=http://www.xn--12clc7clam6fntf7dwcg4b3t4dzae.com]จองตั๋วรถทัวร์ลิกไนท์ทัวร์[/direct] |[direct=http://xn--24-3qid0egh8gc0bd9duce99axa.com]จองตั๋วรถทัวร์ระบบออนไลน์ 24 ชม.[/direct] |[direct=http://busticket-th.com/]จองตั๋ว ซื้อตั๋วรถทัวร์[/direct] [direct=https://จองตั๋ว.net]จองตั๋วรถทัวร์ เช็คราคาตั๋วรถทัวร์[/direct]