mysql_fetch_row issue. Please read.

This is a discussion on mysql_fetch_row issue. Please read. within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Here's a snippet of my script: $result = mysql_query("SELECT count(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-29-2006
sectionFOURTEEN
 
Posts: n/a
Default mysql_fetch_row issue. Please read.

Here's a snippet of my script:

$result = mysql_query("SELECT count(*) FROM cart WHERE
cookieId = '" . GetCartId() . "' AND prod_id = $prod_id"); //line 39
$row = mysql_fetch_row($result);
$numRows = $row[0];

I'm getting the "supplied argument is not a valid MySQL result resource
on line 39" error. I know it's getting returned because there aren't
any records that match this query. However, I would like it to return
zero records instead of this error. I have the rest of the script setup
to handle zero records returned but, this error is being returned
instead. This script works when there are records to return.

I was thinking about an if statement possibly but, I'm not sure which
direction to go with this.

Any help would be greatly appreciated!

Reply With Quote
  #2 (permalink)  
Old 03-29-2006
Colin McKinnon
 
Posts: n/a
Default Re: mysql_fetch_row issue. Please read.

sectionFOURTEEN wrote:

> Here's a snippet of my script:
>
> $result = mysql_query("SELECT count(*) FROM cart WHERE
> cookieId = '" . GetCartId() . "' AND prod_id = $prod_id"); //line 39
> $row = mysql_fetch_row($result);
> $numRows = $row[0];
>
> I'm getting the "supplied argument is not a valid MySQL result resource
> on line 39" error. I know it's getting returned because there aren't
> any records that match this query. However, I would like it to return
> zero records instead of this error. I have the rest of the script setup
> to handle zero records returned but, this error is being returned
> instead. This script works when there are records to return.
>


Off the top of my head...

$numRows = (integer)$row[0];

?

C.


Reply With Quote
  #3 (permalink)  
Old 03-29-2006
diogo86@gmail.com
 
Posts: n/a
Default Re: mysql_fetch_row issue. Please read.

this error message doesn't seem to be about no records found but a sql
error on the query.

try this:

$res = mysql_query("SELECT count(*) FROM cart WHERE
cookieId = '" . GetCartId() . "' AND prod_id = $prod_id") or
die(mysql_error());

$numRows = mysql_num_rows($res) ? mysql_result($res,0) : 0;

mysql_free_result($res);

when you correct the query and it's no longer returning an error you
show remove " or die(mysql_error())" to avoid relevant data to be show
to the user just in case it has an error.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:04 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0