Forum Moderators: coopster

Message Too Old, No Replies

How important are PHP Warnings?

         

too much information

7:18 am on Jan 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have set my error reporting to E_ALL and I'm getting a warning about a MySQL call "Unable to jump to row 0 on MySQL result index..." but the data loads with no trouble other than the warning.

Is this something I should worry about? I can't seem to find a way to avoid the warning other than turning error reporting off.

$SQL = "select * from reminders order by reminderSend";
$reminderResults = mysql_query($SQL);
$reminderCount = mysql_num_rows($reminderResults);
...
for ($i = 0; $i < $reminderCount; $i++) {
mysql_result($reminderResults,$i,"reminderID")
};
...

So basically I'm trying to list all of my reminders after first getting a count to see if there are any at all. Am I doing this wrong?

maxximus

11:26 am on Jan 18, 2008 (gmt 0)

10+ Year Member



The mysql_result function is only efficient if you intend retrieving specific rows from a resultset.

In this case your just retieving all rows from resultset 'reminders'.

Best pracice to use mysql_fetch* functions with a while loop. [uk.php.net...]

<?php
$SQL = "select * from reminders order by reminderSend";
$reminderResults = mysql_query($SQL);
while ($reminder = mysql_fetch_object($reminderResults)) {
echo $reminder ->reminderID;
}?>

too much information

6:01 pm on Jan 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the code, I tried using mysql_fetch after posting last night but it gave me even more warnings. Until your example I couldn't find an example of how it should be used.

So if I understand correctly, if I want to loop through a set of data (reminders for example) and also display a name associated with the reminder (in a client table for example) should I use mysql_result for that if I'm only pulling one value from the table?

eelixduppy

7:17 pm on Jan 18, 2008 (gmt 0)



It doesn't matter all that much how you do it. mysql_result or one of the mysql_fetch_* will pretty much give you the same results with little code difference. Sometimes one function is better to use than the other, but from what you described both seem like decent choices.

Back to the original question for a second. First off, you should not be allowing the errors to appear in a browser on a production server so if that is the case you should be immediately start logging those errors. If you do have a lot of scripts that have a lot of warnings coming from them, then maybe you'd want to lessen your error reporting level in your php.ini file so that your error logs aren't going to fill up so quickly and will only contain more crucial information. I tend to always log everything and be as strict as possible with my error reporting, so I log everything, but I also make sure that I don't have any warnings in my code at all. Most of the time warnings will not cause any problems to your actual application itself, but sometimes it could create issues.

If you'd like to post your new code, then I'm sure we can get those warnings fixed up for you :)

too much information

5:47 am on Jan 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is not running on a production server, it's a project I'm developing and after upgrading to PHP 5.2 from 4.* I had to turn on the error reporting to deal with the parts of my code that were honestly not put together as solidly as they should have been.

I was just curious to see how critical it was to clean up all of the warnings and if there was something I was doing wrong because it never hurts to learn a new way to do things.

I haven't had a chance to work on that part of my code yet, so I don't have any code to post yet, but when I get back to it I'll be sure to add it here.