uwannadonkey Posted February 18, 2008 Share Posted February 18, 2008 <?php include('inc/header.php'); echo"--- Food---<br>"; $result=mysql_query('SELECT * FROM food WHERE owner = $user->ID and name = Apple'); if (mysql_num_rows($result) >= 1) { $apple = mysql_num_rows($result); echo " Apples($apple)"; } include('inc/footer.php'); ?> thats the code for counting apples, but this comes out: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/trukki4/public_html/averyel/inventory.php on line 8 Quote Link to comment https://forums.phpfreaks.com/topic/91683-mysql-count-rows/ Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 replace $result=mysql_query('SELECT * FROM food WHERE owner = $user->ID and name = Apple'); with $result=mysql_query('SELECT * FROM food WHERE owner = $user->ID and name = Apple') or die(mysql_error()); and tell us what it says Quote Link to comment https://forums.phpfreaks.com/topic/91683-mysql-count-rows/#findComment-469555 Share on other sites More sharing options...
uwannadonkey Posted February 18, 2008 Author Share Posted February 18, 2008 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>ID and name = Apple' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/91683-mysql-count-rows/#findComment-469558 Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 silly me i should of noticed, you are using ' quotes instead of " for your query, you cannot include $variables without concatenating with single quotes, you have 2 options: either: $result=mysql_query("SELECT * FROM food WHERE owner = $user->ID and name = Apple"); or concatenate: $result=mysql_query('SELECT * FROM food WHERE owner = '.$user->ID.' and name = Apple'); Quote Link to comment https://forums.phpfreaks.com/topic/91683-mysql-count-rows/#findComment-469563 Share on other sites More sharing options...
uwannadonkey Posted February 18, 2008 Author Share Posted February 18, 2008 Unknown column 'Apple' in 'where clause' but there is a column apple.. this is a copy of the mysql table: ID owner name effect bonus 1 1 Apple 5 energy 2 1 Apple 2 energy 3 1 Apple 5 energy Quote Link to comment https://forums.phpfreaks.com/topic/91683-mysql-count-rows/#findComment-469572 Share on other sites More sharing options...
uwannadonkey Posted February 18, 2008 Author Share Posted February 18, 2008 fixed $apple1= Apple; $result=mysql_query("SELECT * FROM food WHERE owner = $user->ID AND name = 'Apple'")or die(mysql_error()); if (mysql_num_rows($result) >= 1) { $apple = mysql_num_rows($result); echo " Apples($apple)"; } apple needed a 'apple' to work Quote Link to comment https://forums.phpfreaks.com/topic/91683-mysql-count-rows/#findComment-469583 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.