 |
สอบถามการดึงตารางในฐานข้อใ(ค้นหา) เพราะเหตุใดมันจึงไม่แสดง |
|
 |
|
|
 |
 |
|
Form Show DATA
Code
<table width="920" border="1" cellspacing="0">
<tr bgcolor="#f3f1eb" bordercolor="#00CC99">
<th width="87" align="center"> รหัสลูกค้า </th>
<th width="120" align="center"> ชื่อ - นามสกุล</th>
<th width="50" align="center"> เบอร์ </th>
<th width="150" align="center"> ที่อยู่ </th>
<th width="30" align="center"> ตำบล/แขวง </th>
<th width="30" align="center"> อําเภอ/เขต </th>
<th width="30" align="center"> จังหวัด</th>
<th width="30" align="center">ไปรษณีย์</th>
<?php
if($listdata == "S/N"){
echo "<th width='70' align='center'> S/N </th>";
}
?>
<th width="70" align="center"> แก้ไข</th>
<th width="10" align="center"> ดูข้อมูล</th>
</tr>
<?
while($result = mysql_fetch_array($query))
{
?>
<tr>
<td align="center"><?=$result["cus_id"];?></td>
<td><?=$result["cus_firstname"] . " " . $result["cus_lastname"];?></td>
<td><?=$result["cus_mobilephone"];?></td>
<td align="left"><?=$result["cus_address"];?></td>
<td align="left"><?=$result["district"];?></td>
<td align="left"><?=$result["amphur"];?></td>
<td align="left"><?=$result["province"];?></td>
<td align="center"><?=$result["cus_postalcode"];?></td>
<?php
if($listdata == "S/N"){
echo "<td align='center'>$result[serial_number]</td>";
}
?>
<td align="center"><a href="customer_edit.php?cus_id=<?=$result["cus_id"]?>">แก้ไข</a></td>
<!--<td align="center"><a href="customer_view.php?cus_id=<?=$result["cus_id"]?>">ดูข้อมูล</a></td>-->
</tr>
<?
}
?>
</table>
////////
Code (PHP)
$SQL = "select cus.cus_id,cus.cus_firstname , cus.cus_lastname ,(select provinceName from elvira_crm.province where provinceId = cus.cus_province) as province , (select districtName from elvira_crm.district where districtId = cus.cus_district) as district , (select amphurName from elvira_crm.amphur where amphurId = cus.cus_sub_district) as amphur, cus_address,cus_postalcode , cus.cus_mobilephone from elvira_crm.customer as cus ";
if($listdata == "รหัสลูกค้า") ปกติ
{
$SQL .= " WHERE cus_id LIKE '%$text%' order by cus_id asc";
}
else if($listdata == "ชื่อ") ปกติ
{
$SQL .= " WHERE cus_firstname LIKE '%$text%' order by cus_id asc";
}
else if($listdata == "เบอร์โทรศัพท์") ปกติ
{
$SQL .= " WHERE cus_mobilephone LIKE '%$text%' order by cus_id asc";
}
else if($listdata == "อําเภอ/เขต") **** ไม่ออก
{
$SQL = "select districtName from elvira_crm.district where districtId = cus.cus_district as district , (select amphurName from elvira_crm.amphur where amphurId = cus.cus_sub_district) as amphur where districtName LIKE '%$text%' order by cus_id asc";
}
[img]Code
[/img]
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2014-03-11 10:13:06 |
By :
Rokies |
View :
845 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอาคำสั่ง sql ไป query ใน phpmyadmin ดูก่อนครับ ว่ามันแสดงออกมาหมดหรือเปล่า หรือไม่ก็ลองดีบั๊กไปทีละจุดๆเอาครับ
|
 |
 |
 |
 |
Date :
2014-03-11 10:21:47 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใกล้วความจริงแล้วครับ ลองคิวรี่ดูแล้วครับ
ตามนี้ครับ
Code (PHP)
SELECT cus.cus_id, cus.cus_firstname, cus.cus_lastname, (
SELECT provinceName
FROM elvira_crm.province
WHERE provinceId = cus.cus_province
) AS province, (
SELECT districtName
FROM elvira_crm.district
WHERE districtId = cus.cus_district
) AS district, (
SELECT amphurName
FROM elvira_crm.amphur
WHERE amphurId = cus.cus_sub_district
AND amphurName LIKE 'บางกะปิ' //ส่วนที่ใช้ทดสอบ
) AS amphur, cus_address, cus_postalcode, cus.cus_mobilephone
FROM elvira_crm.customer AS cus
ผลออกมาดังรูปครับ

คำถาม ถ้าต้องการให้โชว์ข้อมูลที่มี amphurName LIKE 'บางกะปิ' อย่างเดียวต้องทำอย่างไรครับ
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2014-03-12 10:24:15 |
By :
Rokies |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอรบกวนด้วยนะครับ พอดีลืมล็อกอิน
|
 |
 |
 |
 |
Date :
2014-03-12 10:27:56 |
By :
midnightsara |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ เพิ่ม IS NOT NULL ต่อท้าย
Code (PHP)
SELECT cus.cus_id, cus.cus_firstname, cus.cus_lastname, (
SELECT provinceName
FROM elvira_crm.province
WHERE provinceId = cus.cus_province
) AS province, (
SELECT districtName
FROM elvira_crm.district
WHERE districtId = cus.cus_district
) AS district, (
SELECT amphurName
FROM elvira_crm.amphur
WHERE amphurId = cus.cus_sub_district IS NOT NULL
AND amphurName LIKE 'บางกะปิ'
) AS amphur, cus_address, cus_postalcode, cus.cus_mobilephone
FROM elvira_crm.customer AS cus
|
 |
 |
 |
 |
Date :
2014-03-12 10:37:41 |
By :
midnightsara |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผลลองดึงโค๊ดชุดนี้เข้าไปใส่ใน PHP แต่พอค้นหา มันไม่ส่งค่ามาให้เหมือนลองใน PHPmyadmin เลยครับ
Code (PHP)
SELECT cus.cus_id, cus.cus_firstname, cus.cus_lastname, (
SELECT provinceName
FROM elvira_crm.province
WHERE provinceId = cus.cus_province
) AS province, (
SELECT districtName
FROM elvira_crm.district
WHERE districtId = cus.cus_district
) AS district, (
SELECT amphurName
FROM elvira_crm.amphur
WHERE amphurId = cus_sub_district IS NOT NULL
AND amphurName LIKE '%บางกะปิ%'
ORDER BY amphurName ASC
) AS amphur, cus_address, cus_postalcode, cus.cus_mobilephone
FROM elvira_crm.customer AS cus
ในPHP
Code (PHP)
else if($listdata == "amphur"){
$SQL = "SELECT cus.cus_id, cus.cus_firstname, cus.cus_lastname, (
SELECT provinceName
FROM elvira_crm.province
WHERE provinceId = cus.cus_province
) AS province, (
SELECT districtName
FROM elvira_crm.district
WHERE districtId = cus.cus_district
) AS district, (
SELECT amphurName
FROM elvira_crm.amphur
WHERE amphurId = cus_sub_district IS NOT NULL
AND amphurName LIKE '%$text%'
ORDER BY amphurName ASC
) AS amphur, cus_address, cus_postalcode, cus.cus_mobilephone
FROM elvira_crm.customer AS cus ";
ขอผู้ชี้แนะครับ
|
 |
 |
 |
 |
Date :
2014-03-12 13:37:15 |
By :
midnightsara |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|