我在这里有一个搜索脚本,需要使用 MySQL 和 PHP 在多个表中搜索短语/单词。name
正在搜索的列列在表中都是相同的。任何帮助将不胜感激,下面是我的代码:
<?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');
?>