newttster Posted October 24, 2011 Share Posted October 24, 2011 $tablets=mysql_query("SELECT inv_qty FROM inventory WHERE inv_itemid='620' && inv_userid='$userid' LIMIT 1"); $tabletsone=mysql_num_rows($tablets); You now have {$tabletsone} metal tablets left. I am trying to get it to print out the number of item (620) that are in the inventory file. It returns a value of 1 every time. I've tried using fetch_array and fetch_assoc as well. Quote Link to comment Share on other sites More sharing options...
Maniak Posted October 24, 2011 Share Posted October 24, 2011 I haven't coded in months, but try removing LIMIT 1 from the query? Quote Link to comment Share on other sites More sharing options...
sniko Posted October 24, 2011 Share Posted October 24, 2011 I have never seen "&&" used in mysql... May be worth changing. to AND use_up_some_characters_so_i_can_post Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted October 24, 2011 Share Posted October 24, 2011 (edited) {$tabletsone} should be {$tabletsone['inv_qty']} If your wanting the item number it would be {$tabletsone['inv_itemid']} take off the limit on your query and change the && to AND as sniko stated. Edited October 24, 2011 by lucky3809 Quote Link to comment Share on other sites More sharing options...
Ishraq Posted October 24, 2011 Share Posted October 24, 2011 LIMIT 1 gathers just 1 count. If you remove that, it will count all. Quote Link to comment Share on other sites More sharing options...
bluegman991 Posted October 24, 2011 Share Posted October 24, 2011 (edited) It is returning 1 because you have "$tabletsone=mysql_num_rows($tablets);". Change this to mysql_fetch_assoc or mysql_fetch_array. $query=mysql_query("SELECT inv_qty FROM inventory WHERE inv_itemid='620' && inv_userid='$userid' LIMIT 1"); $tablets=mysql_fetch_assoc($query); echo "You have $tablets[inv_qty] metal tablets left!"; Edited October 24, 2011 by bluegman991 Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted October 24, 2011 Share Posted October 24, 2011 (edited) $tablets=mysql_query("SELECT inv_qty FROM inventory WHERE inv_itemid='620' AND inv_userid='$userid'"); $tabletsone=mysql_fetch_assoc($tablets); echo ''.$tabletsone['inv_qty'].''; Edited October 25, 2011 by lucky3809 Quote Link to comment Share on other sites More sharing options...
newttster Posted October 24, 2011 Author Share Posted October 24, 2011 Thank you everyone. I did all the changes that you suggested and it now it returns nothing ... $tablets=mysql_query("SELECT inv_qty FROM inventory WHERE inv_itemid='620' AND inv_userid='$userid'"); $tabletsone=mysql_num_rows($tablets); You now have {$tabletsone['inv_qty']} metal tablets left. Gives me ... You now have metal tablets left. I even added tried changing it to ("SELECT `inv_qty` FROM `inventory` WHERE `inv_itemid`='620' AND `inv_userid`='$userid'",$c) Quote Link to comment Share on other sites More sharing options...
bluegman991 Posted October 24, 2011 Share Posted October 24, 2011 No it wont. It will output how many of that item he has. He had LIMIT 1. Limit 1 means he is only selecting 1 row. Mysql_num_rows counts how many rows were selected. Therefore mysql_num_rows will always be 1 as long as he has limit set to 1. But each item isn't stored in it's own row, it is stored in the inv_qty field. So he needs to fetch the row first. Then output the field in which inv_qty is stored. YOU HAVE TO CHANGE MYSQL_NUM_ROWS to MYSQL_FETCH_ASSOC. Quote Link to comment Share on other sites More sharing options...
newttster Posted October 25, 2011 Author Share Posted October 25, 2011 Thank you bluegman991 changing it to the fetch_assoc with the other changes did it. Thanks again to everyone! Quote Link to comment Share on other sites More sharing options...
bluegman991 Posted October 25, 2011 Share Posted October 25, 2011 ;) No prob. Quote Link to comment 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.