Page 1 of 1

Fixing Data Row Callback [Resolved]

Posted: Fri Sep 13, 2013 7:06 pm
by Epiales
Okay, I have where you can click on your items and it lists the items in the inventory, but the problem is that it lists ALL the items from EVERYONE. I'm not sure how I did that, but it only needs to show what items that specific user has. Here is what code I have for recalling from database.

Code: Select all

<?php
$id = $user['id']; 
$counter = 0;
$invinfo = ("SELECT count(*) as total, name, stats, price, statadd, randid, type FROM inventory GROUP BY name having count(*) > 0 ");
$invinfo2 = mysql_query($invinfo) or die ("Could not select inventory");
while ($row = mysql_fetch_assoc($invinfo2)) {
$cur_item = $row['name'];

 if($row['type'] == 'healing' || $row['type'] == 'revive' )
      {
?>
<div>             
    <div align="left" class="itemleft"><?php echo $row["name"]; ?></div>            
    <div align="center" class="itemcenter"><?php echo $row["total"]; ?></div>
    <div align="center" class="itemright">Adds: <?php echo $row["statadd"]; ?></div>
    <input type="hidden" id="hidden" name="hidden" value="<?php echo $row["id"]; ?>">
    <div align="left"><?php echo "<A href='battle1.php?randid=$row[randid]'?><font color='red'>Use Item" ?></a></font></div>
<br />
</div>
<?php
I tried changing to the code below, but still shows everything in the inventory table:

Code: Select all

$invinfo = ("SELECT count(*) as total, name, stats, price, statadd, randid, type FROM inventory GROUP BY name having count(*) > 0 AND $id= $user[id]");
So, example: I have 3 coffee's under my id, but shows I have a total of 5 coffee's because of the other person that has 2 of them. lol... Not supposed to work that way LOL

Re: Fixing Data Row Callback

Posted: Fri Sep 13, 2013 8:26 pm
by MikuzA
How about..

Code: Select all

$invinfo = ("SELECT count(*) as total, name, stats, price, statadd, randid, type FROM inventory GROUP BY name having count(*) > 0 AND id= $user[id]");
"id = $user[id]" instead of "$id = $user[id]" :)



Edit:

You might need to add a WHERE clause with the ID, before the group.

Re: Fixing Data Row Callback

Posted: Sat Sep 14, 2013 1:30 am
by Epiales
MikuzA wrote:How about..

Code: Select all

$invinfo = ("SELECT count(*) as total, name, stats, price, statadd, randid, type FROM inventory GROUP BY name having count(*) > 0 AND id= $user[id]");
"id = $user[id]" instead of "$id = $user[id]" :)



Edit:

You might need to add a WHERE clause with the ID, before the group.
Thanks, didn't think about the where statement. Fixed:

Code: Select all

$invinfo = ("SELECT count(*) as total, name, stats, price, statadd, randid, type FROM inventory WHERE id = $_SESSION[uid] GROUP BY name having count(*) > 0 ");