Multitable search problem with php

Asked

Viewed 31 times

1

I need to have my script search multiple tables within the same database. I don’t want one table to be related to another or necessarily combined, I just need the site’s search system to search for the word typed by the user in all tables in the database.

X-Bank with 35 tables when the user enters a precise word that this word is searched in all 35 tables of the database and all results in the content column of the 35 tables are removed for the user.

I cannot use any other technology, language or platform than PHP and Mysql.

Below follows the code of my search script resultdo.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 your help with this problem.

Thanks in advance,

Phil

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.