我希望在页面的不同部分回显结果,而不仅仅是在标题中。我该怎么做呢?如果我想分别回收6个项目怎么办?
<?php
require_once 'facebook.php';
$appapikey = 'CENSORED';
$appsecret = 'CENSORED';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();
$user = $user_id;
$i = 0;
$fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user.')';
$_friends = $facebook->api_client->fql_query($fql); // Extract the user ID's returned in the FQL request into a new array.
$friends = array();
if (is_array($_friends) && count($_friends))
{
foreach ($_friends as $friend)
{
$i++;
$friends[] = $friend['uid'];
if ($i<=6) echo $friend['uid']."@[,:m]";
}
}
?>
<br><br>HELLO
答案 0 :(得分:1)
不要echo
。收集字符串变量中的所有输出,并在真正需要时收集echo
。
答案 1 :(得分:1)
如果它位于同一页面上,您只需在页面上的任何位置访问$ _friends变量即可。
require_once 'facebook.php';
$appapikey = <KEY>;
$appsecret = <SECRET>;
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();
$user = $user_id;
$i = 0;
$fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user.')';
$_friends = $facebook->api_client->fql_query($fql); // Extract the user ID's returned in the FQL request into a new array.
$friends = array();
if (is_array($_friends) && count($_friends))
{
foreach ($_friends as $friend)
{
$i++;
if ($i<=6) $friends[] = $friend['uid']."@[,:m]";
}
}
?>
BUNCH OF STUFF
<?php
// You need to display some friend data
foreach($friends as $friend) {
echo $friend;
}
然后用$ friends变量做任何你想做的事。
答案 2 :(得分:0)
将包含echo
语句的循环移动到页面的另一部分,或将结果存储在数组中,稍后再echo
。