Fixing Data Row Callback [Resolved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Fixing Data Row Callback [Resolved]

Post 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
Last edited by Epiales on Sat Sep 14, 2013 1:31 am, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: Fixing Data Row Callback

Post 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.
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Fixing Data Row Callback

Post 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 ");
 
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”