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> <input type="submit" id="downloadbut" value="Follow"></td>
if there are his $friends must show echo '<td> <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> <input type="submit" id="downloadbut" value="Follow"></td>
</form>';
} else {
echo '<td> <span id="liketextvote">Following</span></td>';
}
}
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);
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);