<?
$sql="select prdId as f1,Brand as f2,dateInform as f3 from service where (prdId like '%$searchs%' or Brand like '%$searchs%' or dateInform like '%$searchs%') union select ptId as f1,ptName as f2, ' ' as f3 from producttype where (ptId like '%$searchs%' or ptName like '%$searchs%') ";
$dbquery=mysql_db_query($dbname,$sql);
$num_rows=mysql_num_rows($dbquery);
for ($i=0;$i < $num_rows; $i++) {
$record = mysql_fetch_array($dbquery);
$scId=$record['scId'];
$dateInform=$record['dateInform'];
$prdId = $record['prdId'];
$ptId = $record['ptId'];
$brand=$record['Brand'];
$dateService = $record['dateService'];
$status=$record['status'];
}?>
<?
$sql="select prdId as f1,Brand as f2,dateInform as f3 from service where (prdId like '%$searchs%' or Brand like '%$searchs%' or dateInform like '%$searchs%') union select ptId as f1,ptName as f2, ' ' as f3 from producttype where (ptId like '%$searchs%' or ptName like '%$searchs%') ";
$dbquery=mysql_db_query($dbname,$sql);
$num_rows=mysql_num_rows($dbquery);
if($num_rows != 0){
while($record = mysql_fetch_array($dbquery)){
$scId=$record['scId'];
$dateInform=$record['dateInform'];
$prdId = $record['prdId'];
$ptId = $record['ptId'];
$brand=$record['Brand'];
$dateService = $record['dateService'];
$status=$record['status'];
}
}
?>
<?
$sql="select prdId as f1,Brand as f2,dateInform as f3 from service where (prdId like '%$searchs%' or Brand like '%$searchs%' or dateInform like '%$searchs%') union select ptId as f1,ptName as f2, ' ' as f3 from producttype where (ptId like '%$searchs%' or ptName like '%$searchs%') ";
$dbquery=mysql_db_query($dbname,$sql);
echo $num_rows=mysql_num_rows($dbquery); //ตรงนี้เจอข้อมูลครับ..
if($num_rows != 0){
while($record = mysql_fetch_array($dbquery)){
$scId=$record['scId'];
echo $dateInform=$record['dateInform']; //ตรงนี้ลงไปไม่มีเลยครับ..
echo $prdId = $record['prdId'];
echo $ptId = $record['ptId'];
echo $brand=$record['Brand'];
echo $dateService = $record['dateService'];
echo $status=$record['status'];
}
}
?>
คุณ ต้องระบุ index ให้ถูกครับ คุณใช้ hash และ คนได้ เปลี่ยนชื่อ ฟีลด้วย
ลอง
Code (PHP)
<?php
$sql="select prdId as f1,Brand as f2,dateInform as f3 from service where (prdId like '%$searchs%' or Brand like '%$searchs%' or dateInform like '%$searchs%') union select ptId as f1,ptName as f2, ' ' as f3 from producttype where (ptId like '%$searchs%' or ptName like '%$searchs%') ";
$dbquery=mysql_db_query($dbname,$sql);
echo $num_rows=mysql_num_rows($dbquery); //ตรงนี้เจอข้อมูลครับ..
if($num_rows != 0){
while($record = mysql_fetch_array($dbquery)) echo $record['f1'], $record['f2'], $record['f3'], '<br>';
}
?>
<?php
$sql="select prdId as f1,Brand as f2,dateInform as f3 from service where (prdId like '%$searchs%' or Brand like '%$searchs%' or dateInform like '%$searchs%') union select ptId as f1,ptName as f2, ' ' as f3 from producttype where (ptId like '%$searchs%' or ptName like '%$searchs%') ";Code (PHP)
?>
//ผิดตรงคำสั่ง sql อ่ะครับผม
<?
$sql = "
select prdId as f1,brand as f2,dateinform as f3
from service
where (prdid like '%$searchs%' or Brand like '%$searchs%' or dateInform like '%$searchs%' )
union select ptId as h1,ptName as h2, ' ' as h3
from producttype
where (ptId like '%$searchs%' or ptName like '%$searchs%')
";
$dbquery=mysql_db_query($dbname,$sql);
$num_rows=mysql_num_rows($dbquery);
if($num_rows != 0){
while($record = mysql_fetch_array($dbquery)){
$scId=$record['f1'];
$dateInform=$record['f2'];
$prdId = $record['f3'];
$ptId = $record['h1'];
$brand=$record['h2'];
}
}
?>
ประมาณนี้ครับ
ลองดูครับ เพราะว่าคุณใช้คำสั่ง as ค่าตัวแปร f1 ซ้ำกันครับ