AND THE DISPLAY FRIENDS FUNCTION MENTIONED IN THE NEXT FUNCTION
function displayfriends($major, $friends) {
// Whatever markup you want here
// For example -- unordered list
if (count($friends) > 0) {
echo "<h2>Friends with $major major</h2>";
echo '<ul>';
foreach ($friends as $friend) {
echo "<li>$friend</li>";
}
echo '</ul>';
}
}
THIS IS A TEST FUNCTION TO WORK WITH THE UI
function getFriendsWithMajor($major) {
$config = array(
'appId' => '',
'secret' => '',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
try {
$fql = "select uid,name,education from user WHERE uid IN (select uid2 from friend where uid1=($user_id))";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
} catch(Exception $o) {
d($o);
}
$friends = $fqlResult;
$friends_BA = array();
foreach ($friends as $friend) {
if (is_array($friend['education'])) {
foreach ($friend['education'] as $school) {
if (isset($school['concentration'])) {
foreach ($school['concentration'] as $concentration) {
if (strpos(strtolower($concentration['name']), $major) !== false) {
$friends_BA[] = $friend['name'];
continue 3; // skip to the next friend
}
}
}
}
}
}
$this->displayfriends($major);
}
Here’s the output I’m getting:
Warning: Missing argument 2 for social::displayfriends(), called in /home/content/07/8316707/html/class.Social.php on line 234 and defined in /home/content/07/8316707/html/class.Social.php on line 183
Keep in mind, when I did $this->displayfriends($major, $friends) it only returned one result when it should have returned 15.
I think I understand what you’re looking for. You basically just need to understand php arrays, and how to use parameters with functions. print_r is a debugging tool that generates the output you see. For use of your array data, you should handle it directly. Simplest way is to foreach through it. I made a separate function for the display just to reinforce both concepts.
Display function
Calling the functions: