I am getting the following error on my home page. I am new to php code and this one is looking pathetic on my wordpress site. any help would be highly appreciated. The error is as below:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given on line 39

The code on line 39 is as follows:

                $post_db_table_name = $wpdb->prefix . "posts";
                $total_deals = mysql_query("select p.* from $post_db_table_name p where p.post_type = 'seller' and p.post_status = 'publish' ");
                $total_pages = mysql_num_rows($total_deals); *line 39*
                $recordsperpage = $post_number;
                $pagination = $_REQUEST['pagination'];
                if($pagination == '') {

Please help me. Thank you very much in advance.

Like pritaeas said,
if( ! $total_deals ) die("Query failed.")
or
if( $result = mysql_query("") ) { /* ... */ }

Thanks @pritaeas and @Unimportant. I am a newbie here, so not sure where I should be pasting the error checking code. @Unimportant: please help me here. Should I paste the code you have provided to line 40?

It seems to me that it may be that your SQL statment is failing so the mysql_query is returning a boolean value of false instead of a result set. Check to make sure that your SQL statement is valid.

If there are no deals, what's $total_pages?

Replace line 2 with:

$total_deals = mysql_query("select p.* from $post_db_table_name p where p.post_type = 'seller' and p.post_status = 'publish' ") or die(mysql_error());

and show the error message.

Thank you so much @pritaeus, @JorgeM and @Unimportant. I learnt something in the past one day struggle, and is because of your help only. As @pritaeus said I tried to add the below code yesterday itself and it worked. But after I closed the cpanel the problem persisted.

or die(mysql_error());

I wanted to try again adding the above code anyway, but before that I wanted to try if it is fixed automatically, as it was earlier working fine. And 'just like how nature works' it has cured itself - it worked somehow and the site is opening now. I havent made any changes in the code, but it works fine now.

Although I am not sure about how it got fixed, your suggestions I believe would help me understand it better. I am trying to add google pagespeed service to my site - do you think this would have caused any effect?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.