Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.