SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need some help with a PHP loop

    I'm using the loop below, and echo $fbml produces what I expect, but the $fbml variable that's in:
    "$facebook->api_client->profile_setFBML($fbml, $users[$i])"
    seems to always be equal to "hello!!!".

    for ($i = 0; $i < count($users); $i++) {
    $username = $users[$i];
    $fbml = 'hello' . $username . '!!!<br/>';
    echo $fbml;
    $facebook->api_client->profile_setFBML($fbml, $users[$i]);
    }

    This updates all the profile's of all my facebook apps users, and is updating all of them with the string "hello!!!", instead of "hello[username]!!!". So does the above code look find, it seems to me that it would have to be some weird thing that facebook is doing.. but just wanted to make sure there wasn't something wrong with the code above.

    Thanks in advance!

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Where's $users come from? It looks like the array is empty or doesn't exist at all.
    Saul

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Where's $users come from? It looks like the array is empty or doesn't exist at all.
    Ok, what i realize it's doing now is that whatever the $username value is on the last loop is what $username is equal to on every single loop. Before the last loop had just been producing a blank value for $username, but now that I've changed the number of user for it to loop through, the last value is no longer blank, and i can see that it is being set in each loop. Isn't this odd?

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hm, well, try changing it a bit:
    Code php:
    $c=count($users);
    for ($i = 0; $i < $c; $i++) {
      $username = $users[$i];
      $fbml = 'hello' . $username . '!!!<br/>';
      echo $fbml;
      $facebook->api_client->profile_setFBML($fbml, $users[$i]);
    }

    Although, that can hardly change anything. Can you do print_r($users); to show how the array looks like?
    Saul

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry the issue was something dumb i was doing. thanks for the help though!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •