Jump to content

[SOLVED] unexpected T_FOREACH error


nitromaster

Recommended Posts

Have a problem here with a facebook app. I had a add.php file which basically got photos from facebook via their api depending on get parameters (aid, pid, owner, etc) and then inserting data into my db if it passed in all info basically.

 

Problem was I was outputting all photos/albums to a single row. In another topic I got a helpful reply giving me a pretty good idea of where I should be going with the code.

 

 

This is what I have as my main add.php now with a unexpected t_foreach error.

(I originally had only one add.php with if statements depending on what was present but I'm going for multiple ones until i get this sorted at least :) )

<?php

// Requiring facebook api lib + app config
require_once 'facebook.php';
require_once 'config.php';

// Defining the facebook object with api key and secret and defining user_id as logged in-added user.

$facebook = new Facebook($FACEBOOK_API, $FACEBOOK_SECRET);
$user_id = $facebook->require_add();

$profile_id = $user_id;
$profile_type = Member;

echo '<table>';
$columns = 5;
$currCol = 1;
$photos = $facebook->photos_getAlbums($profile_id, '');
$total = count($photos)
foreach($photos as $userData)
{
   if ($currCol==1)
   {
      echo "<tr>\n";
   }

	echo '<td><div style="text-align: center; padding: 10px;">
<a href="http://apps.facebook.com/appname/add1.php?fb_page_id=' . $page_id . '&aid={$userData['aid']}&owner={$userData['owner']}">
<sn:photo pid=\"{$userData['cover_pid']}\" size="s" /><br/>
<a href="http://apps.facebook.com/appname/add1.php?fb_page_id=' . $page_id . '&aid={$userData['aid']}&owner="{$userData['owner']}">
{$userData['name']}</a><br/>{$userData['size']} photos</div></td>';

   if ($currCol==$columns)
   {
      echo "<tr>n";
      $currCol=0;
   }
   $currCol++;
}

echo '</table>';

?>

 

 

$photos is returned as:

Array
(
    [0] => Array
        (
            [aid] => 91107396551212
            [cover_pid] => 911075535353
            [owner] => 1
            [name] => "A"
            [created] => 1223671096000
            [modified] => 1223671219000
            [description] => 
            [location] => 
            [link] => "http://www.facebook.com/photos?aid=91107396551212"
            [size] => 1
        )
    [1] => Array
        (
            [aid] => 91153507613520
            [cover_pid] => 91423743263186
            [owner] => 1
            [name] => "B"
            [created] => 1223671234000
            [modified] => 1223671248000
            [description] => 
            [location] => 
            [link] => "http://www.facebook.com/photos?aid=91153507613520"
            [size] => 1
        )
)

from the api

 

 

Link to comment
Share on other sites

$total = count($photos)

 

Thanks

removed that line and I'm getting closer.

 

Now getting

 

PHP Parse error:  syntax error, unexpected T_STRING, expecting ',' or ';'

on line

<a href="http://apps.facebook.com/appname/add1.php?fb_page_id=' . $page_id . '&aid={$userData['aid']}&owner={$userData['owner']}">

(i removed the blank fb_page_id parameter in my tests as well to rule out any problems there)

 

 

 

 

Link to comment
Share on other sites

Don't take this the wrong way, but that's your second syntax error in a row.  Perhaps you should look into the syntax of PHP.

 

 

 

I don't feel like finding the error, but it looks like a quote error, or something of that nature.

Both bits of code that there was problems with were copy/pastied from elsewhere without me properly checking them.

 

Got it sorted now, thanks for fixing that :)

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.