Re: Invalid MySQL result resource
| From: | David Robley | Date: | Thu, 13 Sep 2001 04:52:56 +0000 |
| Subject: | Re: Invalid MySQL result resource | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-67125@lists.php.net to get a copy of this message | ||
On Thu, 13 Sep 2001 14:15, Dan Harrington wrote:
> > -----Original Message-----
> > From: speedboy [mailto:speedboy@nomicrosoft.org]
> > Sent: Wednesday, September 12, 2001 10:27 PM
> > To: php-general@lists.php.net
> > Subject: Re: [PHP] Invalid MySQL result resource
> >
> > > "Supplied argument is not a valid MySQL result resource in ..... on
> > > line 52"
> > >
> > > Line 52 is the line where I fetch the row from the second query.
> >
> > Don't keep doing a mysql_connect on each loop.
>
> ....thats whats weird about this,
>
> I'm not.
>
> Here's what's going on.
> ========================================================
>
> $connection = mysql_connect($server, $user, $pass);
> mysql_select_db($db);
>
> $query = "select * from shoppingcart where PHPSESSID = '$PHPSESSID'";
> $result = mysql_query($query,$connection);
> $numrows = mysql_num_rows($result);
>
> $count = 0;
>
> while ($count < $numrows){
> $cartitem = mysql_fetch_array($result);
> $productquery = "select * from products where productid =
> '$cartitem[productid]'"; $productresult = mysql_query($productquery);
Ah. Should that be $cartitem[$productid] ??? And perhaps better written
as
$productquery = "select * from products where productid =
'" . $cartitem[productid] . "'";
to be sure that the array element is dereferenced properly.
> $productinfo = mysql_fetch_array($productresult); //THIS line produces
> the error $count++;
> }
>
> mysql_close($connection);
>
> ========================================================
>
> I don't get it. I must be blind or something because I just don't
> see whats causing this.
>
> Thanks again,
> Dan
--
David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA
Half the lies they tell me aren't true. --Yogi Berra