[MySql/PHP] Parsing array items with comma

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chenci
Forum Newbie
Posts: 5
Joined: Sun Jul 26, 2009 4:50 pm

[MySql/PHP] Parsing array items with comma

Post by chenci »

Hi, i've been working in this code and it seems to have some problems. This is what i want to do
1)A query to select all the users who have recievemail = YES
2)Fetch all the email from the query to an array and put commas to one after another
3)The echo would be something like this
[email]google@gmail.com,microsoft@hotmail.com,newguy@new.com[/email],and so on

Code: Select all

$query = "SELECT * FROM " .s('prefix'). "users WHERE recievemail = 'YES' ORDER BY id DESC";
$result  = mysql_query($query);
$n[] = mysql_fetch_array($result);
    foreach ($n as $e)
    {
        $mails = $e['email'];
        $multiplemails .= $mails . ",";
        echo $multiplemails;
    } 
And this is what i got

Code: Select all

messinanahuel@hotmail.com,
Very weird isn't it? Only one email, and i went to phpmyadmin and there a lot of users with recieve mail = YES. Seems not touching PHP for half a year, can get you now a dose of insanity with this code, as i can't figure out where is wrong.
Any ideas? Thanks for the time anyway.
Chenci
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: [MySql/PHP] Parsing array items with comma

Post by jackpf »

You'll need to put your mysql_fetch_array() in a while loop if you want to retrieve multiple rows.
chenci
Forum Newbie
Posts: 5
Joined: Sun Jul 26, 2009 4:50 pm

Re: [MySql/PHP] Parsing array items with comma

Post by chenci »

thanks, now it worked putting with arrays.
Post Reply