 |
ข้อมูลมันแสดงไม่ครบ ใส่ลูปให้มันแล้วนะครับ...มันออกมาเป็น 1 1 1 1 1 1 1 1 1 1 1 1 1 ... ที่จริงต้องออกเป็น 1 2 3 4 5 6 7 |
|
 |
|
|
 |
 |
|
มันออกมาเป็น
1 1 1 1 1 1 1 1 1 1 1 1 1 ...
ที่จริงต้องออกเป็น
1 2 3 4 5 6 7
Code (PHP)
$strSQL = "SELECT top(100) detail.ThaiName, detail.EngName, tel.tel, fax.fax, contact.con_name, contact.c_name, contact.c_lastname, contact.c_add,
contact.c_province, contact.c_amphur, contact.c_district, contact.c_zip, contact_tel.c_tel
FROM detail INNER JOIN
tel ON detail.id_detail = tel.id_detail INNER JOIN
fax ON detail.id_detail = fax.id_detail INNER JOIN
contact ON detail.id_detail = contact.id_detail INNER JOIN
contact_tel ON contact.id_con = contact_tel.id_con
WHERE detail.Enable='T' AND detail.IsActive='T' AND
(tel.tel LIKE '%".$keyword[0]."%' or fax.fax LIKE '%".$keyword[0]."%' or contact_tel.c_tel LIKE '%".$keyword[0]."%' or detail.hotline LIKE '%".$keyword[0]."%')
and
(tel.tel LIKE '%".$keyword[1]."%' or fax.fax LIKE '%".$keyword[1]."%' or contact_tel.c_tel LIKE '%".$keyword[1]."%' or detail.hotline LIKE '%".$keyword[1]."%')
and
(tel.tel LIKE '%".$keyword[2]."%' or fax.fax LIKE '%".$keyword[2]."%' or contact_tel.c_tel LIKE '%".$keyword[2]."%' or detail.hotline LIKE '%".$keyword[2]."%')
and
(tel.tel LIKE '%".$keyword[3]."%' or fax.fax LIKE '%".$keyword[3]."%' or contact_tel.c_tel LIKE '%".$keyword[3]."%' or detail.hotline LIKE '%".$keyword[3]."%')
and
(tel.tel LIKE '%".$keyword[4]."%' or fax.fax LIKE '%".$keyword[4]."%' or contact_tel.c_tel LIKE '%".$keyword[4]."%' or detail.hotline LIKE '%".$keyword[4]."%')
and
(tel.tel LIKE '%".$keyword[5]."%' or fax.fax LIKE '%".$keyword[5]."%' or contact_tel.c_tel LIKE '%".$keyword[5]."%' or detail.hotline LIKE '%".$keyword[5]."%')
and
(tel.tel LIKE '%".$keyword[6]."%' or fax.fax LIKE '%".$keyword[6]."%' or contact_tel.c_tel LIKE '%".$keyword[6]."%' or detail.hotline LIKE '%".$keyword[6]."%')
and
(tel.tel LIKE '%".$keyword[7]."%' or fax.fax LIKE '%".$keyword[7]."%' or contact_tel.c_tel LIKE '%".$keyword[7]."%' or detail.hotline LIKE '%".$keyword[7]."%')
and
(tel.tel LIKE '%".$keyword[8]."%' or fax.fax LIKE '%".$keyword[8]."%' or contact_tel.c_tel LIKE '%".$keyword[8]."%' or detail.hotline LIKE '%".$keyword[8]."%')
and
(tel.tel LIKE '%".$keyword[9]."%' or fax.fax LIKE '%".$keyword[9]."%' or contact_tel.c_tel LIKE '%".$keyword[9]."%' or detail.hotline LIKE '%".$keyword[9]."%')";
if($_GET["txtKeyword2"]!= "")
{
$strSQL .= " and (detail.province LIKE '%".$_GET["txtKeyword2"]."%') ";
}}
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mssql_fetch_array($objQuery))
mssql_result($objQuery,$i,"tel")." ";
}
Tag : PHP, Ms SQL Server 2008
|
|
 |
 |
 |
 |
Date :
2011-08-27 15:37:53 |
By :
MyZeus |
View :
856 |
Reply :
19 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณลูปผิดตำแหนงนะครับถ้าแบบนั้นน่ะ ลองไลโค๊ดดูดีๆครับ
|
 |
 |
 |
 |
Date :
2011-08-27 15:41:55 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เฉลยเลยได้ไหมครับ ตาลาย
|
 |
 |
 |
 |
Date :
2011-08-27 15:44:12 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแบบนี้นะครับวาได้ไม๊
Code (PHP)
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mssql_fetch_array($objQuery)) {
mssql_result($objQuery,$i,"tel")." ";
}
}
|
 |
 |
 |
 |
Date :
2011-08-27 15:46:45 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เหมือนเดิมครับ 1 1 1 1 1 1 1 1 ....
|
 |
 |
 |
 |
Date :
2011-08-27 15:51:39 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใส่ while มันไม่น่าจะออกข้อมูลซำนะครับเนี่ย - -* ปวดหัวอีกละ
|
 |
 |
 |
 |
Date :
2011-08-27 19:26:27 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$i บวกมันด้วยครับ
mssql_fetch_array fetch ออกมาแล้ว ใยไปใช้ mssql_result 
|
 |
 |
 |
 |
Date :
2011-08-27 22:53:12 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันออกอย่างนี้อะครับ
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8
ที่จริงต้อง 1 2 3 4 5 6 7 8
|
 |
 |
 |
 |
Date :
2011-08-27 23:21:38 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
sql ถ้ามี join อย่าลืม group by.
|
 |
 |
 |
 |
Date :
2011-08-28 00:45:21 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เมื่อเราเรียกฟิวด์อะไรมา เราก็ต้อง group by ตัวนั้นด้วยใช่มะครับ ผมลอง group by แล้ว ก็เหมือนเดิมเลยครับ
|
 |
 |
 |
 |
Date :
2011-08-28 10:14:25 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
group by อันที่เป็น primary key ของ table หลัก
|
 |
 |
 |
 |
Date :
2011-08-28 14:45:11 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้ครับ ผมลองใน sql server2008 อะคับ
|
 |
 |
 |
 |
Date :
2011-08-28 16:36:52 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$strSQL = "...";// อ้างอิงจากข้างบน
$result = mssql_query($strSQL);
while ( $row = mssql_fetch_array($result) ) {
echo $row['tel'] . " ";
}
ลองดูนะครับ
|
 |
 |
 |
 |
Date :
2011-08-28 16:47:42 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้ครับ ผม งง มาก ลองดูตารางคร่าวๆของผมนะครับ
ตารางdetail
id_detail=132
ThaiName=ธุรกิจ1
ตารางtel
id_tel=1
tel=1,2,3,4,5,6,7,8(มี 8 เรคคอร์ด 8 เบอร์ครับ)
id_detail=132
ตารางfax
id_fax=1
fax=2,3,5(มี 3 เรคคอร์ด 3 เบอร์ครับ)
id_detail=132
สรุปคือ ธุรกิจนี้มีเบอร์โทร 8 เบอร์ 3 แฟกซ์
เหมือนกับว่ามันไล่เช็คว่า...
ธุรกิจ1 เบอร์1 แฟกซ์2
ธุรกิจ1 เบอร์1 แฟกซ์3
ธุรกิจ1 เบอร์1 แฟกซ์5
ธุรกิจ1 เบอร์2 แฟกซ์2
ธุรกิจ1 เบอร์2 แฟกซ์3
ธุรกิจ1 เบอร์2 แฟกซ์5 อย่างงี้อะครับ เบอร์เลยออกมา 1 1 1 2 2 2 3 3 3 ประมาณนี้ แก้ได้ไหมครับ
|
 |
 |
 |
 |
Date :
2011-08-28 17:23:50 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอ capture รูปข้อมูลในฐานมาดูได้มั้ยครับ ดูอย่างงี้ผมไม่ชิน
แล้วก๊อปผลล่าสุดที่แก้แล้ว+ โค้ดล่าสุดที่เกี่ยวข้องด้วยครับ
ผมจะพยายามดูให้
|
 |
 |
 |
 |
Date :
2011-08-28 21:21:38 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตาราง detail

ตาราง tel

ตาราง fax

Code ที่แก้ล่าสุด
Code (PHP)
$strSQL = "SELECT detail.ThaiName, detail.EngName, detail.word, detail.type, detail.orther, detail.Address, detail.province, detail.amphur, detail.district, detail.zip,
detail.mail, detail.web, detail.hotline, detail.busi, detail.bg, detail.service, detail.etc, detail.detail, detail.price, detail.branch, detail.commonday, detail.holiday,
detail.note, detail.town1, detail.town2, detail.town3, detail.town4, detail.rate, detail.Created, detail.CreatedBy, detail.CreatedTime, detail.Updated,
detail.UpdatedBy, detail.UpdatedTime, detail.IsSecret, detail.IsActive, detail.Enable, detail.Deleted, detail.DeletedBy, detail.DeletedTime, tel.tel, fax.fax, contact.con_name, contact.c_name, contact.c_lastname, contact.c_add,
contact.c_province, contact.c_amphur, contact.c_district, contact.c_zip, contact_tel.c_tel
FROM detail INNER JOIN
tel ON detail.id_detail = tel.id_detail INNER JOIN
fax ON detail.id_detail = fax.id_detail INNER JOIN
contact ON detail.id_detail = contact.id_detail INNER JOIN
contact_tel ON contact.id_con = contact_tel.id_con
WHERE detail.Enable='T' AND detail.IsActive='T' AND
(tel.tel LIKE '%".$keyword[0]."%' or fax.fax LIKE '%".$keyword[0]."%' or contact_tel.c_tel LIKE '%".$keyword[0]."%' or detail.hotline LIKE '%".$keyword[0]."%')
and
(tel.tel LIKE '%".$keyword[1]."%' or fax.fax LIKE '%".$keyword[1]."%' or contact_tel.c_tel LIKE '%".$keyword[1]."%' or detail.hotline LIKE '%".$keyword[1]."%')
and
(tel.tel LIKE '%".$keyword[2]."%' or fax.fax LIKE '%".$keyword[2]."%' or contact_tel.c_tel LIKE '%".$keyword[2]."%' or detail.hotline LIKE '%".$keyword[2]."%')
and
(tel.tel LIKE '%".$keyword[3]."%' or fax.fax LIKE '%".$keyword[3]."%' or contact_tel.c_tel LIKE '%".$keyword[3]."%' or detail.hotline LIKE '%".$keyword[3]."%')
and
(tel.tel LIKE '%".$keyword[4]."%' or fax.fax LIKE '%".$keyword[4]."%' or contact_tel.c_tel LIKE '%".$keyword[4]."%' or detail.hotline LIKE '%".$keyword[4]."%')
and
(tel.tel LIKE '%".$keyword[5]."%' or fax.fax LIKE '%".$keyword[5]."%' or contact_tel.c_tel LIKE '%".$keyword[5]."%' or detail.hotline LIKE '%".$keyword[5]."%')
and
(tel.tel LIKE '%".$keyword[6]."%' or fax.fax LIKE '%".$keyword[6]."%' or contact_tel.c_tel LIKE '%".$keyword[6]."%' or detail.hotline LIKE '%".$keyword[6]."%')
and
(tel.tel LIKE '%".$keyword[7]."%' or fax.fax LIKE '%".$keyword[7]."%' or contact_tel.c_tel LIKE '%".$keyword[7]."%' or detail.hotline LIKE '%".$keyword[7]."%')
and
(tel.tel LIKE '%".$keyword[8]."%' or fax.fax LIKE '%".$keyword[8]."%' or contact_tel.c_tel LIKE '%".$keyword[8]."%' or detail.hotline LIKE '%".$keyword[8]."%')
and
(tel.tel LIKE '%".$keyword[9]."%' or fax.fax LIKE '%".$keyword[9]."%' or contact_tel.c_tel LIKE '%".$keyword[9]."%' or detail.hotline LIKE '%".$keyword[9]."%')";
if($_GET["txtKeyword2"]!= "")
{
$strSQL .= " and (detail.province LIKE '%".$_GET["txtKeyword2"]."%') ";
}
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mssql_fetch_array($objQuery)) {?>
<?=$objResult["tel"]." ";
}}
?>
|
 |
 |
 |
 |
Date :
2011-08-28 21:44:35 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองละ ทำแบบนี้ทำยังไงก็ไม่ได้ครับ
แต่ของผมออกมาต่างจากคุณ คือมันออกมา 2 3 5 7 8 2 3 5 7 8 ซ้ำๆไปเรื่อยๆ 40 รายการ
ถ้าคุณต้องการแสดงรายการจากตาราง detail แล้วไล่วน tel ของ detail นั้น ให้ออกจนหมด
คุณก็ต้อง loop tel ต่างหาก โดย where id_detail = อ้างอิงแทนที่จะเอามา join กันแบบนี้นะครับ
|
 |
 |
 |
 |
Date :
2011-08-29 03:59:14 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งี้ผม JOIN ตารางแล้ว search ก็ไม่ได้สินะครับ
|
 |
 |
 |
 |
Date :
2011-08-29 08:38:13 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รอผู้เชี่ยวชาญ sql มาช่วยตอบหน่อย
|
 |
 |
 |
 |
Date :
2011-08-29 12:02:10 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|