search multiple tables

ismail · Feb 28, 2012
bang Ellyx saya minta tolong..
saya punya 3 tabel, n mau search multiple table.
tiap tidak berelasi.
saya bingung,, nanti yang dipanggil untuk ditampilkannya apa ya?? ini tabelnya.

tabel internet_access:
in_id,
employee_id,
upload_id,
date,
time,
business_purpose

tabel computer_access:
ca_id,
employee_id,
upload_id,
date,
time,
business_purpose,
access_request

tabel computer_commnication_purchase :
cc_id,
employee_id,
upload_id,
date,
purpose_request,
type_install,
equipment,
description_hw,
reason,
business_purpose

dan ini potongan kodenya.

...
if ($_POST['keyword']!=""){
$sall="select * from internet_access where MATCH(business_purpose) AGAINST ('".$_POST['keyword']."') order by in_id DESC 
UNION
select * from computer_access where MATCH(business_purpose) AGAINST ('".$_POST['keyword']."') order by ca_id DESC
UNION
select * from computer_communication_purchase where MATCH(business_purpose) AGAINST ('".$_POST['keyword']."') order by ca_id DESC ";
$qall=mysql_query($sall) or die (mysql_error());


semua memliki kesamaan pada business purpose.
nah bagaimana saya menampilkan semuanya?? makasih.
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Mar 14, 2012 · 0 Suka · 0 Tidak Suka
Cara yang termudah adalah jangan menggunakan query union, seperti:
if($_POST['keyword']){
	echo "Search in internet_access";
	$q = mysql_query("select * from internet_access where MATCH(business_purpose) AGAINST ('".$_POST['keyword']."') order by in_id DESC");
	while($data = mysql_fetch_array($q)){
	// tampilkan data internet_access
	}

	echo "Search in computer_access";
	$q = mysql_query("select * from computer_access where MATCH(business_purpose) AGAINST ('".$_POST['keyword']."') order by ca_id DESC");
	while($data = mysql_fetch_array($q)){
	// tampilkan data internet_access
	}

	echo "Search in computer_communication_purchase";
	$q = mysql_query("select * from computer_communication_purchase where MATCH(business_purpose) AGAINST ('".$_POST['keyword']."') order by ca_id DESC");
	while($data = mysql_fetch_array($q)){
	// tampilkan data internet_access
	}
	
}