Reputation: 1520
I have this code: ids row is like ( 54,88,15,78) a string concat of id:
$sql = "SELECT *, ids FROM.....";
$results = $Database->Select($sql);
$last = end($results);
foreach($results as $i){
$userArray = explode(",",$i['ids']);
if( in_array($_SESSION['AUTH_ID'], $userArray) ){
echo $i['name'];
if($last != $i)
echo ",\n";
}
}
This prints always a comma after $i['name']
... this is wrong.. how can i fix it?? How can I count in_array
new value??
Upvotes: 0
Views: 159
Reputation: 19118
There is an easier way to do this:
/* ... */
$logged_in[] = array();
if( in_array($_SESSION['AUTH_ID'], $userArray) ){
$logged_in[] = $i['name'];
}
echo implode(', ', $logged_in);
This prints Alice, Bob
Upvotes: 7