$search=$_POST["txtKeyword"];
$search_sub=substr($search,4); //ในกรณีตัด เลขหน้าออก 4 ตัว
include "../../include/connect.php";
$sql="select * from tb_order o INNER JOIN tb_department d ON d.dep_id=o.ref_dep_id INNER JOIN tb_dep_detail dd ON dd.dep_detail_id=o.ref_dep_detail_id WHERE 1";
if(!empty($dep_id) ){
$sql.=" AND d.dep_id='$dep_id' ";
}
if(!empty($_POST["txtKeyword"])){
$sql.=" AND ( o.order_id LIKE '%".$_POST["txtKeyword"]."%' OR o.order_id LIKE '%".$search_sub."%' )";
}
$result=mysql_db_query($dbname,$sql);
นี่รูปครับ
นี่เป็น SQL ถ้าพิมพ์ 00001 ครับ Code (SQL)
select * from tb_order o INNER JOIN tb_department d ON d.dep_id=o.ref_dep_id INNER JOIN tb_dep_detail dd ON dd.dep_detail_id=o.ref_dep_detail_id WHERE 1 AND ( o.order_id LIKE '%00001%' OR o.order_id LIKE '%1%' ) ORDER BY o.order_id DESC LIMIT 0 , 10
select * from tb_order o INNER JOIN tb_department d ON d.dep_id=o.ref_dep_id INNER JOIN tb_dep_detail dd ON dd.dep_detail_id=o.ref_dep_detail_id WHERE 1 AND ( o.order_id LIKE '%1%' OR o.order_id LIKE '%%' ) ORDER BY o.order_id DESC LIMIT 0 , 10