|
 |
|
สอบถามเรื่องการ Query ข้อมูลแบบหลายเงื่่อนไข .............ช่วยดูโค้ดหน่อยน่ะค่ะว่า ผิดตรงไหน หามา 2 ชม.กว่าเเล้ว |
|
 |
|
|
 |
 |
|
Code (PHP)
$strSQL = "SELECT invasion.id, month.month_name, division.division_name, bss.bss_name,line.line_name,pole,type.type_name,style.style_name,height,barrier,detail,detected,status.status_name,deadline,name,address,tel
FROM invasion
INNER JOIN month ON invasion.month_id=month.month_id
INNER JOIN division ON invasion.division_id = division.division_id
INNER JOIN bss ON invasion.bss_id = bss.bss_id
INNER JOIN line ON invasion.line_id = line.line_id
INNER JOIN type ON invasion.type_id = type.type_id
INNER JOIN style ON invasion.style_id = style.style_id
INNER JOIN status ON invasion.status_id = status.status_id
where 1=1";
if(isset($_GET['month']) and !empty($_GET['month']))
{
$strSQL .= " and month_id = '" . $_GET['month'] . "%'"
}
if(isset($_GET['division']) and !empty($_GET['division']))
{
$strSQL .= " and division_id = '" . $_GET['division'] . "%'"
}
เมื่อเลือกเดือน แต่ไม่ได้เลือก แผนก ก็ให้แสดงเดือนที่เราเลือกรวมทั้งจำนวนแผนกทั้งหมด
อีกโค้ดนึงค่ะ
$strSQL = "SELECT invasion.id, month.month_name, division.division_name, bss.bss_name,line.line_name,pole,type.type_name,style.style_name,height,barrier,detail,detected,status.status_name,deadline,name,address,tel
FROM invasion
INNER JOIN month ON invasion.month_id=month.month_id
INNER JOIN division ON invasion.division_id = division.division_id
INNER JOIN bss ON invasion.bss_id = bss.bss_id
INNER JOIN line ON invasion.line_id = line.line_id
INNER JOIN type ON invasion.type_id = type.type_id
INNER JOIN style ON invasion.style_id = style.style_id
INNER JOIN status ON invasion.status_id = status.status_id
where (invasion.month_id = '".$_GET["month"]."' and invasion.division_id = '".$_GET["division"]."' and invasion.bss_id = '".$_GET["bss"]."' and invasion.line_id = '".$_GET["line"]."' and invasion.type_id = '".$_GET["type"]."'and invasion.style_id = '".$_GET["style"]."'and invasion.status_id = '".$_GET["status"]."')";
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2011-12-09 14:48:20
|
 |
 |
 |
 |
Date :
2011-12-09 14:46:11 |
By :
lookpla26 |
View :
798 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Join โหดจังครับ ออกแบบฐานข้อมูลใหม่ดีไม๊? 
|
 |
 |
 |
 |
Date :
2011-12-09 15:07:16 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอรายละเอียดเพิ่มเติมครับ
แล้วก็ เป็นระบบเกี่ยวกับอะไร
ต้องการให้เป็นยังไง
แล้วที่ว่าผิดอะครับ ผิดยังไง
แล้วอีกอย่าง ก็คือ ส่วยมากจะเห็นว่าจะเป็นการ INNER JOIN ทั้งหมดเลยนะครับ
|
 |
 |
 |
 |
Date :
2011-12-09 16:17:08 |
By :
nerobenz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป็นระบบจัดการข้อมูลสิ่งรุกล้ำ (ในเขตเสาไฟฟ้าแรงสูง)
user ต้องการให้ระบบสามารถค้นหาข้อมูลได้ในทุกกรณีตั้งแต่ ค้นหาตามเดือน ตามแผนก ตามแนวสายไฟฟ้า ตามสถานะ แต่ที่เอาโค้ดมาให้ดู เอามาให้ดูเฉพาะ ค้นหาตามเดือนและแผนก
แต่โค้ดที่หนูเขียนนั้น มันค้นได้กรณีที่ ใส่ทั้งเดือนและแผนก ผลลัพท์จึงจะออกอ้ะค้ะ หนูต้องการให้ใส่เฉพาะเดือนผลลัพท์ก็ออก ใส่เฉพาะแผนกผลลีพท์ก้อ ออกอ้ะค้ะ
|
 |
 |
 |
 |
Date :
2011-12-13 08:30:37 |
By :
lookpla26 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|