Reputation: 5148
this is what i am trying to do :
$allwinnersarra = array(26809,26805,24279,4839,20939,17678,4999,17745,1);
$results_query = mysql_query("SELECT username FROM table_users WHERE userid IN('".join("','", $allwinnersarra)."')");
while ($row = mysql_fetch_array($results_query)) {
$usernamesFound.= $row['username'];
}
die($usernamesFound);
there is an array of id numbers and I want their usernames , in my own idea my approach is correct but the outcome is not.
The output is only the first username and does not show other usernames
Upvotes: 1
Views: 1476
Reputation: 6003
Try this:
$allwinnersarra = array(26809,26805,24279,4839,20939,17678,4999,17745,1);
$allwinnersarra = implode( ',', $allwinnersarra );
$sql = "SELECT username FROM table_users WHERE userid IN
(" . mysql_real_escape_string( $allwinnersarra ) . ");";
Hope it helps...
Upvotes: 3
Reputation: 605
I would suggest you putting the usernames in an array
$users = array();
while($row = mysql_fetch_array($results_query)) { $users[] = $row['username']; }
Upvotes: 2