Jump to content
MakeWebGames

Returns wrong value.


Recommended Posts

$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.

Link to comment
Share on other sites

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 by bluegman991
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.   Paste as plain text instead

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