0

UPDATE: Still can't seem to figure it out. If anyone can lend a hand, it would be appreciated ^^.

I am having a problem and I'm not sure where my code is breaking down. I have a 'follow' function where you can follow different registered users. Their userID's of who you followed are stored in an array (follower_array). It's retrieving each member from the array, but of each member that's followed instead of displaying all the content, it's only displaying the 1 latest one from each member.

$broadcastList= "";

if ( $follower_array != "" ) {

  $followArray = explode(",", $follower_array);
  $followCount = count($followArray);   
  $i = 0;
  $broadcastList .= "<table>";

  foreach( $followArray as $key => $value ) {

    $i++;
    $sqlName = mysql_query("
        SELECT username, fullname 
          FROM members 
         WHERE id='$value' 
         LIMIT 1
    ") or die ("error!");

    while ( $row = mysql_fetch_array($sqlName) ) {
      $friendUserName = substr($row["username"],0,12);
    }

    $sqlBroadcast = mysql_query("
        SELECT mem_id, bc, bc_date, device 
          FROM broadcast 
         WHERE mem_id='$value' 
      ORDER BY bc_date ASC 
         LIMIT 50
    ") or die ("error!");

    while ( $bc_row = mysql_fetch_array($sqlBroadcast) ) {
      $mem_id  = $bc_row['mem_id'];
      $bc      = $bc_row['bc'];
      $dev     = $bc_row['device'];
      $bc_date = $bc_row['bc_date'];
      $broadcastList .= "<td><a href='member.php?id=' .$value. ''>
      $friendUserName</a> &bull; $when_bc &bull; Via: $dev <b>$bc</b></td></tr>";
    }
    broadcastList .= "</table>";
  }
}

So, it's retrieving the members entirely, but not more than their single latest "broadcast." Any insight would be appreciated.. thank you!

6
  • 3
    Programming is not a contest to see how much stuff you can cram into each line. Indent code blocks on a new line (especially if you're going to bother using {}'s) and keep your code properly indented. Commented Jun 30, 2011 at 22:29
  • 5
    ..and for everybody else, who thinks differently, there is perl-golf. Commented Jun 30, 2011 at 22:31
  • Just a second.. There's no contest? I was under the assumption that I would get a stackoverflow badge for the longest lines! :). My Apologies, code has been edited to be more friendly. Commented Jun 30, 2011 at 22:35
  • 1
    @Matthew: No offense, but that wasn't much improvement. Commented Jun 30, 2011 at 22:39
  • 1
    @x3ro: Edited again. Now that's how it's supposed to look , IMO... Commented Jun 30, 2011 at 22:52

2 Answers 2

2

Here's what's happening:

while( $row = some_next_result_function() ){
    $result = $row["thing"];
}

Is going to overwrite $result every time, so you'll only end up with the last result.

You need to make a list and append to it instead.

Sign up to request clarification or add additional context in comments.

4 Comments

I had a sinking feeling it was something as simple as that. Thank you!
Unfortunately I changed the $row result but still only coming back with 1 result.
Well you're deliberately retrieving 1 friendUserName. Are you sure that you have more than one broadcast for that user?
Yes, I have dummy data entered in for 10 broadcasts per user.
0

I'm gonna take a shot in the dark:

$broadcastList .= "<td><a href='member.php?id=' .$value. ''>
  $friendUserName</a> &bull; $when_bc &bull; Via: $dev <b>$bc</b></td></tr>";

That line pretty much misses a starting "tr" element. Are you sure the content isn't shown simply because of the faulty html markup?

Also:

broadcastList .= "</table>";

You're missing the $ there ;).

I don't know if this fixes it or even helps you; but I sure hope so :). Alternatively; you can also check the HTML source to see if the entries really aren't there (see first remark).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.