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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums 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! |
|
|||
|
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. |
|
|||
|
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. |