mysqli - foreach loop returning ghost results php sql -


i have table in database called 'users' column in table 'friend_array'. column stores usernames of users once become friends. way data in column looks ",user_name,user_name,user_name,user_name,"

the issue having follows:

i taking friend array, exploding @ ',' fetching information relating each result.

take @ code

public function getfriends($user_to_check) {      $pull= mysqli_query($this->connection, "select friend_array users username ='$user_to_check'");         confirm($pull);         $userpull = fetch_array($pull);      $value = $userpull['friend_array'];     $result = explode(",", $value);     foreach($result $newvalue) {           $query= mysqli_query($this->connection, "select * users username ='$newvalue'");         confirm($query);         $row = mysqli_fetch_assoc($query);         $image = $row['profile_pic'];         $username = $row['username'];         echo "<li><a href='$username'>                 <div class='thumbnail-wrapper d32 circular b-white m-r-5 b-a b-white'>                   <img width='35' height='35' data-src-retina='$image' data-src='$image' src='$image'>                 </div>                 </a>               </li>";     }    }  

so can see echos out html each users profile picture. query working fine, please can express dont need lecture on prepared statements pdo or of jazz, own personal use.

what happens code returns blank result infront of , behind actual results. please see image understand mean

enter image description here

i'm missing simple,and apologise if case.

thank in advance.

the explode() method separates string after each delimiter in case: ,user_name,user_name,user_name,user_name, first comma , last comma indicating there word, empty.

the solution save friend_array user_name,user_name,user_name,user_name (without first , last comma)


Comments