I have a search script here, that needs to search multiple tables for a phrase/word using MySQL and PHP. The column name
column that is being searched is all the same across tables. Any help would be appreciated and here is my code below.
<?php
$filter = $_REQUEST['query'];
mysql_connect($hostname,$username, $password) or die ("<script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script>");
mysql_select_db($dbname);
$query = 'SELECT * FROM (SELECT `name` FROM `voxmoviesfilestable`) a UNION (SELECT `name` FROM `voxadultfilestable`) b UNION (SELECT `name` FROM `voxmixesfilestable`) c UNION (SELECT `name` FROM `voxconcertsfilestable`) d UNION (SELECT `name` FROM `voxmp3filestable`) e UNION (SELECT `name` FROM `voxfilestable`) WHERE `name` REGEXP \''.$filter.'\' ORDER BY `name`;';
$maxquery = 'SELECT count(*) as cnt FROM `voxmoviesfilestable`, `voxadultfilestable`, `voxmixesfilestable`, `voxconcertsfilestable`, `voxmp3filestable`, `voxfilestable` WHERE `name` REGEXP \''.$filter.'\';';
$result = mysql_query($query) or die ('Error accessing Database');
?>
$query = 'SELECT * FROM WHERE REGEXP \''.$filter.'\' ORDER BY name;';
– asprin Mar 9 at 6:29SELECT * FROM WHERE REGEXP ...
. Is there any relation between these tables in the second query? – Mahmoud Gamal Mar 9 at 6:34name
...voxfilestable
) ) WHEREname
REGEXP...` – Buttle Butkus Mar 9 at 9:03