Jump to content

mysql_num_rows


thomashw

Recommended Posts

Can someone tell me why I keep getting the error "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result" using this code:

 

<?
$id = intval($_GET['product_id']);
$result = mysql_query("SELECT * FROM product, manufacturer_image WHERE product_id={$id}, manufacturer_image.manufacturer_id=product.manufacturer_id");
if(mysql_num_rows($result) > 0) {
while($image = mysql_fetch_assoc($result)) {
echo "<p align=\"center\" class=\"shipping-head\"><img src=\"$image[image]\" width=\"130px\">";
}}
else {
echo "Hey";
}
?>

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/84922-mysql_num_rows/
Share on other sites

You need to use AND, not a comma:

 

<?php
$id = intval($_GET['product_id']);
$result = mysql_query("SELECT * FROM product, manufacturer_image WHERE product_id={$id} AND manufacturer_image.manufacturer_id=product.manufacturer_id") or die(mysql_error());//always try adding an or die statement if you're having mysql troubles
if(mysql_num_rows($result) > 0) {
while($image = mysql_fetch_assoc($result)) {
echo "<p align=\"center\" class=\"shipping-head\"><img src=\"$image[image]\" width=\"130px\">";
}}
else {
echo "Hey";
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/84922-mysql_num_rows/#findComment-432984
Share on other sites

Can someone tell me why I keep getting the error "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result" using this code:

 

<?
$id = intval($_GET['product_id']);
$result = mysql_query("SELECT * FROM product, manufacturer_image WHERE product_id={$id}, manufacturer_image.manufacturer_id=product.manufacturer_id");
if(mysql_num_rows($result) > 0) {
while($image = mysql_fetch_assoc($result)) {
echo "<p align=\"center\" class=\"shipping-head\"><img src=\"$image[image]\" width=\"130px\">";
}}
else {
echo "Hey";
}
?>

 

Thanks!

 

Because your query is failing and you fail to check its return value prior to using it.

Link to comment
https://forums.phpfreaks.com/topic/84922-mysql_num_rows/#findComment-432986
Share on other sites

You need to use AND, not a comma:

Thank you! I thought since you use a comma after the FROM statement, you'd use a comma there too. Guess not!

 

I also didn't know about the mysql_error(); statement.

 

This is the only forum I've ever been apart of where I can expect a reply right away. I love it. Hopefully I'm good enough soon to help out, too.

Link to comment
https://forums.phpfreaks.com/topic/84922-mysql_num_rows/#findComment-432994
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.