tags:

views:

90

answers:

5

I have a PHP script vieworder.php that includes other scripts at the top.

<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";
//...
?>

I get an error on this PHP script. It tells me this:

Warning: mysql_num_rows(): supplied argument ... in vieworder.php on line 185

Do I need to refer only to line 185 of that vieworder.php script or do I need to take into account the included scripts? I am guessing the latter?

Also when it says "Warning" - can I pretty much ignore it? Or is this something I should be very concerned with?

I notice this error causes other errors for me such as:

Warning: Division by zero in ... vieworder.php on line 340

I am guessing its because 0 rows have been returned.

Apologies, for this messy question but I am noob and things are inter-related.

Update

So everyone can see this:

The first occurrence of mysql_num_rows() in vieworder.php is line 235. On line 185 there is an empty line and before that all the way to the top there is only 1 mysql_query?!!

Update 2

I will actually put this in another question.

+2  A: 
Warning: mysql_num_rows(): supplied argument ... in vieworder.php on line 185

Means that you should look for the error around line 185 in vieworder.php, not in any of the included files.

Warnings may be ignored, but it's rarely a good idea, they're there for a reason.

Silfverstrom
A: 

"in vieworder.php on line 185" means "line 182 of the file vieworder.php".
In most/all cases you shouldn't ignore warnings. In this case it most likely means that a prior mysql_query() failed and you do not have a valid result set.

VolkerK
The first occurrence of mysql_num_rows() in vieworder.php is line 235 which baffles me and is the reason I asked this question. On line 182 there is an empty line and before that there is only 1 mysql_query? I am getting confused?!!
Abs
A: 

The error that you're getting:

Warning: mysql_num_rows(): supplied argument ... in vieworder.php on line 185

is actually very specific. You don't need to take anything else into account. If you check out vieworder.php, there is a problem with the code on line 185. One of the arguments being passed to mysql_num_rows() isn't valid, and while it can run, you are likely going to get bad results, so you should look into it.

Clearing the first problem up will likely clear up the problems farther down as well.

zombat
+1  A: 

A supplied argument is not a valid MySQL result resource is often caused by a preceding MySQL query that failed for some reason and mysql_query returned a false instead of the MySQL resource.

So you might want to check if the query was successful (see mysql_error and mysql_errno) before you do anything with that MySQL resource.

Gumbo
mysql_error came in very handy. I know where the problem is. Thanks. :)
Abs
If until now you haven't used mysql_error()/checked the return value of mysql_query you seriously might want to consider PDO for future projects (not only for this reason). You can set the error mode to PDO::ERRMODE_EXCEPTION. If a query fails (which by now you have to catch by testing the return value and using mysql_error) a PDO exception is thrown. It's much harder to miss...
VolkerK
A: 

Also when it says "Warning" - can I pretty much ignore it? Or is this something I should be very concerned with?

As long as you get any kind of "error", be it "error", "warning", or even "notice", you shoud not ignore it :

  • if you get some kind of "error", it can mean you have a more serious error somewhere else
    • for instance, the first warning you're posting can mean your SQL query failed
  • every "error" has some cost on performances / speed

If you can, you should always develop using E_ALL reporting level ; and displaying errors to help you see them. It can be configured via php.ini :

error_reporting = E_ALL
display_errors = On
html_errors = On

On the other side, on your production environment, you sould never display errors ; but you should log them to a file (and check that file sometimes). In your php.ini file :

display_errors = Off

; Besides displaying errors, PHP can also log errors to locations such as a
; server-specific log, STDERR, or a location specified by the error_log
; directive found below. While errors should not be displayed on productions
; servers they should still be monitored and logging is a great way to do that.
; Default Value: Off
; Development Value: On
; Production Value: On
; http://php.net/log-errors
log_errors = On

; Log errors to specified file. PHP's default behavior is to leave this value
; empty.
; http://php.net/error-log
; Example:
error_log = php_errors.log

Some of those can be configured at runtime with ini_set, btw.

Pascal MARTIN