Jump to content

[SOLVED] Need to output arrays received to multiple lines.


nitromaster

Recommended Posts

I have code which uses the facebook api to grab a users photos (each album = an array) and it then outputs each one like

<td><div style="text-align: center; padding: 10px;"><a href="http://apps.facebook.com/appname/add.php?aid=' . $photos[$c]["aid"] . '"><fb:photo pid="' . $photos[$c]["cover_pid"] . '" size="s" /><br/><a href="http://apps.bebo.com/myphotos-dev/add.php?aid=' . $photos[$c]["aid"] . '">' . $photos[$c]["name"] . '</a><br/>' . $photos[$c]["size"] . ' photo' . $plural . '</div></td>

Basically each one onto a td, with the <table><tr> before all of the tds, and </tr></table> after.

 

This means all the albums are outputted onto one row/tr.

Seemed ok for my tests, but it seems some users have a lot of photoalbums and this then streches horizontially a lot with a large number.

 

Full code is

echo '<table><tr>';
$photos = $facebook->photos_getAlbums($profile_id, '');
$total = count($photos);
for($c=0; $c<$total; $c++)
{
	if ($photos[$c]["size"] != 1)
	{
		$plural = "s";
	}
	else
	{
		$plural = "";
	}
	echo '<td><div style="text-align: center; padding: 10px;"><a href="http://apps.facebook.com/add.php?aid=' . $photos[$c]["aid"] . '&owner=' . $photos[$c]["owner"] . '"><sn:photo pid="' . $photos[$c]["cover_pid"] . '" size="s" /><br/><a href="http://apps.facebook.com/appname/add.php?aid=' . $photos[$c]["aid"] . '&owner=' . $photos[$c]["owner"] . '">' . $photos[$c]["name"] . '</a><br/>' . $photos[$c]["size"] . ' photo' . $plural . '</div></td>';
}
echo '</tr></table>';

 

I'd need to output like first 5 arrays/albums to one tr, end the tr, and then output 5 more and so on until all the arrays have been outputted.(ending it at the end with </table> of course.

 

Arrays look like such:

Array
(
    [0] => Array
        (
            [aid] => 1457575578
            [cover_pid] => 14141441166
            [owner] => 686868687
            [name] => "My Album"
            [created] => 1218455214700
            [modified] => 1218247474000
            [description] => 
            [location] => 
            [link] => "http://www.facebook.com/photolink.php?aid=1457575578"
            [size] => 1
        )
    [1] => Array
        (
            [aid] => 14575750
            [cover_pid] => 14147478466
            [owner] => 68686868760
            [name] => "Album Name"
            [created] => 1218224348000
            [modified] => 1218227588000
            [description] => 
            [location] => 
            [link] => "http://www.facebook.com/photolink.php?aid=1457575578"
            [size] => 1
        )      
)

(Random details inserted in example arrays above)

 

Thanks

Link to comment
Share on other sites

<?php

$columns = 5;
$currCol = 1;

$photos = $facebook->photos_getAlbums($profile_id, '');

echo "<table>\n";

foreach($photos as $userData)
{
if ($currCol==1)
{
	echo "<tr>\n";
}

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

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

echo "</table>\n";

?>

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.