Php – adding values into an array using a while loop


So what I'm trying to do is create a live friends search. To do this I need an array of names for AJAX to search through.

Heres my while loop.

if($_REQUEST['D'] == 'viewfriends') {
    $FREINDS = array();
    $FRIENDS_QUERY = "SELECT * FROM `FRIENDS` WHERE `USER` = '{$Modules['User']->Username}' AND `STATUS` = 'accepted' ORDER BY `ID` Limit 10 ;";
    $FRIENDS_RESULT = mysql_query($FRIENDS_QUERY);
    if(mysql_num_rows($FRIENDS_RESULT) > 0) {
        while($FRIENDS_ROW = mysql_fetch_assoc($FRIENDS_RESULT)) {
            $sql = "SELECT * FROM `USERS` WHERE `USERNAME` = '{$FRIENDS_ROW['FRIEND']}' ;";
            $REQUEST_ROW = mysql_fetch_assoc(mysql_query($sql));
    echo json_encode($FRIENDS);
    } else {
        echo'<div class="update status">Sorry, You have no friends at this time. sadface.</div>';   

I put the echo $FRIENDS in there as a test, right now it doesn't display anything. Where did I derp?

Best Solution

You can't echo an array. You can use either print_r($friends) to display the whole row of fields requested in the query (you request *) or you can echo $friends['name'] (depending on how you declared name in your database)