fighnight Posted January 10, 2008 Share Posted January 10, 2008 I am having this trouble, I am trying to make an list of how many stuff someone has but I am having this error it shows two rows Like Item Here Amount Baseball Bat 2 Baseball Bat 2 I am trying to make it only display one but I can't figure it out. :[ Quote Link to comment Share on other sites More sharing options...
thomashw Posted January 10, 2008 Share Posted January 10, 2008 Can you post the code you're using? I'd say you should use a loop with a $counter variable. Quote Link to comment Share on other sites More sharing options...
fighnight Posted January 10, 2008 Author Share Posted January 10, 2008 <tr><td> Item </td> <td> Amount </td> </tr> $item_info= mysql_query("SELECT * FROM item WHERE owner='1'"); while($iteminfo= mysql_fetch_array($item_info) { $result1 = mysql_query("SELECT * FROM item WHERE item = '$iteminfo[item]'"); $idu=mysql_num_rows($result1); echo "<tr><td>$iteminfo[item]</td><td>$idu</td></tr>"; } Very Weird but ehh.... Quote Link to comment Share on other sites More sharing options...
thomashw Posted January 10, 2008 Share Posted January 10, 2008 Are you just trying to display how many items are in the item table under that owner? <? echo '<tr><td>Item Amount</td></tr> $query = ("SELECT * FROM item WHERE owner='1'"); $result = mysql_query($query); $num_rows = mysql_num_rows($result); echo $num_rows; ?> Or, is there only one item under the owners name, but it's displaying it twice? Or are there two items, but you only want the first displayed? Quote Link to comment Share on other sites More sharing options...
fighnight Posted January 10, 2008 Author Share Posted January 10, 2008 I am doing this. The owner can own 2 or more of the items and my error is showing both. I want it to show only one. Quote Link to comment Share on other sites More sharing options...
robotman321 Posted January 10, 2008 Share Posted January 10, 2008 the while is a loop, it picks everything out that: WHERE owner='1' it means it will keep going no matter what the person. I.e. it will go for a user name fred that is an owner if they own 2 items it will pull that one item once then pull the next item for that user. your statement is only for pulling one item at a time no matter the user. Quote Link to comment Share on other sites More sharing options...
thomashw Posted January 10, 2008 Share Posted January 10, 2008 Try this: <tr><td>Item Amount</td></tr> <? $query = ("SELECT * FROM item WHERE owner='1'"); $result = mysql_query($query); for($count=0; $count<1; ++$count) { while($iteminfo = mysql_fetch_assoc($result)) { echo "<tr><td>$iteminfo[item]</td><td>$idu</td></tr>"; }} ?> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted January 10, 2008 Share Posted January 10, 2008 your code should be I've simplified some things <tr><td> Item </td> <td> Amount </td> </tr> $item_info= mysql_query("SELECT count(*) as count,item FROM item WHERE owner='1' group by item"); while($iteminfo= mysql_fetch_array($item_info) { echo "<tr><td>{$iteminfo['item']}</td><td>{$iteminfo['count']}</td></tr>"; } tell me if it works!!! Quote Link to comment Share on other sites More sharing options...
fighnight Posted January 10, 2008 Author Share Posted January 10, 2008 rajivgonsalves thank you. Your code made it work. Thank you. 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.