0

This PHP code is for cheking for names who user is following.They are his friends or if they are not his $friends must show <td>&nbsp; &nbsp; &nbsp;<input type="submit" id="downloadbut" value="Follow"></td> if there are his $friends must show echo '<td>&nbsp; &nbsp; &nbsp;<span id="liketextvote">Following</span></td>'; if the user is following them. But my problem is I can't get result for $friends. The problem is

Notice: Array to string conversion in C:\xampp\htdocs\Edu\1111111111111\userinfo.php on line 109 Array

. But inside while loop result is: megiantongeorgekatimery - this is example from MySQL database. I don't have idei how can I get this results. Someone can help?

$userfile = $_GET['username'];
$username = $user_data['username'];

if ($username != $userfile) {
    $addfriends = mysql_query("SELECT `follow` FROM `friends` WHERE `username` = '$username' ORDER BY id DESC");
    $friends = array();

    while ($query_row = mysql_fetch_array($addfriends)) {
        $val = $query_row['follow'];
        echo $val; // hier I can get result example five name megiantongeorgekatimery
        $friends[] = $val;
    }

    echo $friends; // hier I can get result example five name megiantongeorgekatimery

    if (!in_array($userfile, $friends)) {
        echo '<form action="addfriends.php?username='.$userfile.'" method="post">
                  <td>&nbsp; &nbsp; &nbsp;<input type="submit" id="downloadbut" value="Follow"></td>
              </form>';
    } else {
        echo '<td>&nbsp; &nbsp; &nbsp;<span id="liketextvote">Following</span></td>';
    }
}
3
  • So you just want to print out "Following" in a loop? Commented Mar 19, 2013 at 19:11
  • Is line 109... if (!in_array($userfile, $friends)) {? What is the value of $userfile? Commented Mar 19, 2013 at 19:15
  • You have a huge security hole in there. Read here how to prevent it: stackoverflow.com/questions/60174/… Commented Mar 19, 2013 at 19:17

2 Answers 2

4

You are trying to echo an array when you do echo $friends.

If that is just a debug statement, use print_r instead

print_r($friends);
Sign up to request clarification or add additional context in comments.

Comments

1

You start out by using $friends as an array.
If you want to print the data out from the array, either loop through it using foreach or join in all together before printing.

foreach ($friends as $friend) {print "$friend<br>";}

OR

print join("<br>",$friends);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.