 |
ค้นหาข้อมูลโดยมี column หนึ่งเก็บตัวเลขไว้แบบนี้ครับ 1,2,3,7,8,10,14,20,22,45 |
|
 |
|
|
 |
 |
|
ค้นหาข้อมูลโดยมี column หนึ่งเก็บตัวเลขไว้แบบนี้ครับ
id1 | 1,2,3,7,8,10,14,20,22,45
id2 | 1,7,14,20,42,60
ผู้ใช้ค้นหาโดยใส่ข้อมูล 1 7 22 45 มาทีเดียว
แล้วจะให้ตรงกับ id1 ต้อง WHERE เงื่อนไขยังไงบ้าง
ขอคำแนะนำหน่อยครับ
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery
|
|
 |
 |
 |
 |
Date :
2014-12-28 18:41:12 |
By :
copyringht |
View :
663 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
$input='1 7 22 45';
$tmp_tb='( select '.str_replace( ' ', ' as id union all select ', $input).' ) as tmp ';
$sql='select y.id, y.search_field from ' . $tmp_tb .
" left join yourtable y on concat( ',', y.search_field , ',' ) like concat( '%,', tmp.id , ',%') ".
" where tmp.id is not null group by y.id ";
echo $sql;
?>
|
 |
 |
 |
 |
Date :
2014-12-28 20:28:26 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบพระคุณครับพี่
|
 |
 |
 |
 |
Date :
2014-12-31 21:59:47 |
By :
copyringht |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|