0
I am making a simple search system that brings only the amounts of results from the specified tables The problem is that it is causing an error due to the different tables and their lines. Check out my script.
$q = $_GET['busca'];
$query= '
SELECT * FROM noticia WHERE noticia_title LIKE "%'.$q.'% or noticia_content LIKE "%'.$q.'%"
UNION
SELECT * FROM eventos WHERE evento_nome LIKE "%'.$q.'% or evento_content LIKE "%'.$q.'%"
UNION
SELECT * FROM albuns WHERE album_name LIKE "%'.$q.'%" or album_descricao LIKE "%'.$q.'%"
';
$result = mysql_query($query);
$count = mysql_num_rows($result);
if ($count == 0) {
echo "Nenhum resultado!";
} else {
if ($count == 1) {
echo "1 resultado encontrado!";
}
if ($count > 1) {
echo "$count resultados encontrados!";
}
while ($dados = mysql_fetch_array($query)) {
echo "";
}
}
The mistake being made is: Warning: mysql_num_rows(): supplied argument is not a Valid Mysql result Resource in
Can someone help me?
You are forgetting to close quotes in two points... 1) SELECT * FROM noticia WHERE noticia_title LIKE "%'. $q. '%" 2) SELECT * FROM events WHERE evento_name LIKE "%'. $q.'%"
– Fernando Souza
@Fernandosouza I made the correction, I had not even noticed. But the error persists. Warning: mysql_num_rows(): supplied argument is not a Valid Mysql result Resource
– Fydellys
tries to do so: mysql_query($query) or die(mysql_error()); and sees what appears
– Fernando Souza
Gave the following error: The used SELECT statements have a Different number of Columns
– Fydellys
The tables [news , events and albums] have the amount of different columns.. if you can edit your question and put the structure of these tables, it will help a lot.
– Fernando Souza
Hello, I put, look !
– Fydellys
So... the mistake you’re having is why you can’t select * from these tables using Union why the number of columns is different..
– Fernando Souza
What I can do to solve this selection and results. It has how to help?
– Fydellys