Re: PHP4 and mysql_fetch_array() - one more try
| From: | Michael Dearman | Date: | Thu, 02 Nov 2000 16:36:00 +0000 |
| Subject: | Re: PHP4 and mysql_fetch_array() - one more try | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-4142@lists.php.net to get a copy of this message | ||
Phil Driscoll wrote:
>
> > $rs_result=mysql_db_query($db,"SELECT * FROM XX WHERE
> > something=$yy",$connection);
> > while($row_result=mysql_fetch_array($rs_result))
> > {
> > do_something();
> > }
> >
> Before you use $rs_result in the mysql_fetch_array call you must check that
> it is non zero (ie that the mysql_db_query worked ok).
> So, change your code along the lines of:
>
> $rs_result=mysql_db_query($db,"SELECT * FROM XX WHERE
> something=$yy",$connection);
> if($rs_result)
> {
> while($row_result=mysql_fetch_array($rs_result))
> {
> do_something();
> }
> }
> else
> {
> echo('something went wrong - here's a clue: '.mysql_error());
> }
>
But since no rows is not false, I thought this was the normal way
to handle it:
if(mysql_num_rows($rs_reslt)
{
while($row_result=mysql_fetch_array($rs_result))
{
do_something();
}
}
else...
Mike D.