Warning: mysql_num_rows() expects Parameter 1 to be Resource, Boolean Given in

Asked

Viewed 7,477 times

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.

  • Pass the second parameter to mysql_query, which can pass parameter of connection_link, then do this job: mysql_query($sql_select_all) or die(mysql_error()) and show us the error.

  • 2

    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..

  • It’s a shame, legacy projects are complicated.

  • 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 use @ before the name so you notify the person. ex: @user

  • @rray, yeah, it’s really complicated. Hello, thanks again, I hadn’t noticed that I marked with @

  • @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.

  • @Perfect Lucas.

Show 4 more comments

2 answers

0


The mistake was here:

 mysql_query($sql_select_all) or die(mysql_error())

By doing this I was able to observe the error in sql and fix.

Thank you all!

-1

Make the following change:

$ret = mysql_query($sql_select_all);
if(!$ret){
    die("Erro de conexao")
}else{
    $total_registros = mysql_num_rows($sql_query_all);
}

Browser other questions tagged

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