Jump to content

Why does this display only 1 result?


TeddyKiller

Recommended Posts

I was just about to post that I had an error, then I thought.. ah damn, Ken2k7 picked up the "IN ="

I forgot to change it. I changed it to an = . Thanks for reminding me mjdamato. :P

 

It works! Long struggle understanding this, but I got it to work. All the variables do as I wanted them too.

 

mjdamato, I changed the *  to the nessecary collums (I needed them all) although I went by roopurts post.

 

Thanks guys!

Link to comment
Share on other sites

$query = "SELECT u.username, u.avatar, us.*
          FROM `users` AS u
          JOIN `user_status` AS us ON u.id = us.user_id
          JOIN `friends` AS f ON us.user_id = f.friend_id 
          WHERE f.user_id = '$user->id'
          ORDER BY us.posted DESC";
$result = mysql_query($query) or DIE("Query:<br />$query<br />Error:<br />".mysql_error());

$first_record = true;
echo "<table>\n";
while($row = mysql_fetch_assoc($result))
{
    if($first_record)
    {
        echo "<tr>\n";
        foreach($row as $header=>$value)
        {
            echo "<th>{$header}</th>\n";
        }
        echo "</tr>\n";
        $first_record = false;
    }
    echo "<tr>\n";
    foreach($row as $value)
    {
        echo "<td>{$value}</td>\n";
    }
    echo "</tr>\n";
}
echo "</table>\n";

Where would my echo be..  Whats the advantage of the $first_record, too? I don't understand.

Link to comment
Share on other sites

your echo would be the third from the bottom, and he is using $first_record to say that "if this is the first record, echo out the field names at the top of the table, otherwise just fill in the values".  Effectivly that's a full substitute code he's got there.

 

Yeah, what he said. The code I provided was only to use for illustrative purposes to see the data being returned from the query to ensure it is what you are wanting/expecting. I leave it up to you to output the results how you need them.

Link to comment
Share on other sites

your echo would be the third from the bottom, and he is using $first_record to say that "if this is the first record, echo out the field names at the top of the table, otherwise just fill in the values".  Effectivly that's a full substitute code he's got there.

 

Yeah, what he said. The code I provided was only to use for illustrative purposes to see the data being returned from the query to ensure it is what you are wanting/expecting. I leave it up to you to output the results how you need them.

Yeah. I thought that, as it looked pretty.. strange to output an echo like mine. Everythings working now anyway.

Thanks.

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.