0
I have a problem with the job mysql_num_rows()
"Warning: mysql_num_rows() expects Parameter 1 to be Resource, Boolean Given"
I’ve been looking up other posts but none could help me. PHP is like this:
//Sistema de paginação
$sql_select_all = "SELECT id, nome, descricao, 'empresa' as empresa, 'empresa' as tipo
FROM tbl_empresa
WHERE id LIKE '%".$colname_Pesquisa."%' OR nome LIKE '%".$colname_Pesquisa."%' OR descricao LIKE '%".$colname_Pesquisa."%'
UNION ALL
SELECT tbl_produto.id, tbl_produto.nome, tbl_produto.descricao, tbl_empresa.nome, 'produto' as tipo
FROM tbl_produto
JOIN tbl_empresa
ON tbl_empresa.id = tbl_produto.tbl_empresa_id
WHERE tbl_produto.id LIKE '%".$colname_Pesquisa."%' OR tbl_produto.nome LIKE '%".$colname_Pesquisa."%' OR tbl_produto.descricao LIKE '%".$colname_Pesquisa."%'";
$sql_query_all = mysql_query($sql_select_all);
//O problema esta aqui
$total_registros = mysql_num_rows($sql_query_all);
I have already checked the select and it is returning me the expected value, so much so that it shows on the page.
I realized that
$total_registros
and
$sql_query_all
I get nothing back;
The code is working perfectly on my localhost (PHP 5.3.0), but when I went to the server (PHP 5.3.29) it appeared this error. I don’t think there’s any difference between these versions that would impact like this.
If anyone can help me I’d be grateful!
Error said query failed, see if any error appears,
mysql_query($sql_select_all) or die(mysql_error());
. Don’t use deprecated function! Prefer Mysqli or PDO.– rray
Pass the second parameter to
mysql_query
, which can pass parameter ofconnection_link
, then do this job:mysql_query($sql_select_all) or die(mysql_error())
and show us the error.– juniorb2ss
rray, tell you that I hate using these deprecated functions or old versions, but I am actually completing a project of someone else, who had already started under these conditions..
– Lucas
It’s a shame, legacy projects are complicated.
– rray
juniorb2ss, it worked! I ended up getting so fixated on the function mysql_num_rows() that I didn’t even realize the issue of the right database.
– Lucas
Lucas use
@
before the name so you notify the person. ex: @user– rray
@rray, yeah, it’s really complicated. Hello, thanks again, I hadn’t noticed that I marked with @
– Lucas
@juniorb2ss, just so as not to leave it on the air, I came across an error that was without database when I made the changes you said. Then I managed to make the corrections here.
– Lucas
@Perfect Lucas.
– juniorb2ss