thomashw Posted January 7, 2008 Share Posted January 7, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/84922-mysql_num_rows/ Share on other sites More sharing options...
GingerRobot Posted January 7, 2008 Share Posted January 7, 2008 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84922-mysql_num_rows/#findComment-432984 Share on other sites More sharing options...
trq Posted January 7, 2008 Share Posted January 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84922-mysql_num_rows/#findComment-432986 Share on other sites More sharing options...
thomashw Posted January 7, 2008 Author Share Posted January 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84922-mysql_num_rows/#findComment-432994 Share on other sites More sharing options...
revraz Posted January 7, 2008 Share Posted January 7, 2008 Most of the time you can just copy/paste answers from the day before. Hopefully I'm good enough soon to help out, too. Quote Link to comment https://forums.phpfreaks.com/topic/84922-mysql_num_rows/#findComment-432997 Share on other sites More sharing options...
JJohnsenDK Posted January 7, 2008 Share Posted January 7, 2008 have to give you an HAHA, LOL, ROLF on that one revraz.... funny stuff :D Quote Link to comment https://forums.phpfreaks.com/topic/84922-mysql_num_rows/#findComment-433025 Share on other sites More sharing options...
thomashw Posted January 7, 2008 Author Share Posted January 7, 2008 Most of the time you can just copy/paste answers from the day before. Hahaha, awesome. Quote Link to comment https://forums.phpfreaks.com/topic/84922-mysql_num_rows/#findComment-433103 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.