Jump to content

[SOLVED] Display one mysql_row


fighnight

Recommended Posts

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

Link to comment
Share on other sites

 

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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";
}}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.