I need to have my script search multiple tables within the same database. I do not want one table to be related to one or necessarily combined, I just need the site search engine to search for the word entered by the user in all the tables in the database.
Bank X with 35 tables when the user enters a precise word that this word is searched in all 35 tables of the bank and all the results in the content column of the 35 tables are exported to the user.
I can not use any other technology, language or platform other than PHP and MySQL.
Below is the code for my search script result.php:
<?php
$db = @mysql_connect("meu host", "meu banco", "minha senha") or die("Erro de conexão: ".mysql_error());
@mysql_select_db("meu banco", $db) or die("Erro de seleção do DB: ".mysql_error());
?>
<?php
if(isset($_POST['botao'])){
$busca = $_POST['busca'];
if($busca == "" or $busca == " "){
header('location:http://www.meudominio.com.br/digitealgoparaabusca.php');
}else{
$busca_dividida = explode(' ',$busca);
$quant = count($busca_dividida);
$id_mostrado = array("");
for($i=0;$i<$quant;$i++){
$pesquisa = $busca_dividida[$i];
$sql = mysql_query("SELECT * FROM busca WHERE conteudo REGEXP '".str_replace(' ','|',$busca)."'");
$quant_campos = mysql_num_rows($sql);
if($quant_campos == 0){
header('location:http://www.meudominio.com.br/nenhumresultado.php');
}else{
while($linha = mysql_fetch_array($sql)){
$id = $linha['id'];
$titulo = $linha['titulo'];
$conteudo = $linha['conteudo'];
if(!array_search($id, $id_mostrado)){
echo "<div class='resultado'>
<p>".$conteudo."</p>
</div>
<br />
";
array_push($id_mostrado, $id);
}
}//do while
}//do else
//for($i;$i<count($id_mostrado);$i++){
//echo $id_mostrado[$i]."<br />";
//}
}//do for
}//so else campo vazio
}//do if botão pressionado
?>
I ask for your help with this problem.
Thank you in advance,
Phil