tags:

views:

33

answers:

4

I have a mysql table in which I keep e-mail addresses. The structure is as follows:

id    ||    email

However, how do I actually output those e-mail addresses, separated by commas, in php?

Thanks in advance for your help!

A: 

Third hit on Google for "php mysql": http://www.freewebmasterhelp.com/tutorials/phpmysql

You probably need to read up on the basics, it's not complicated and will only take a few minutes to glance over it and get you started.

dutt
A: 

Option 1:

$sql = "SELECT GROUP_CONCAT(email ORDER BY email ASC SEPARATOR ', ') AS emails FROM emails";
$res = mysql_query($sql);
list($emails) = mysql_fetch_row($res);

echo $emails;

Option 2, so you can do more with all the emails later on:

$emails = array();

$sql = "SELECT email FROM emails ORDER BY email ASC";
$res = mysql_query($sql);
while ($r = mysql_fetch_object($res)) {
  $emails[] = $r->email;
}

// as a list
echo implode(', ',$emails);

// or do something else
foreach ($emails as $email) {
  // ...
}
Alec
A: 

Do something like:

while ($output = mysql_fetch_array($query_results)) {
  echo $output['id'] . ", " . output['email'];
}
Glenn Nelson
+1  A: 

Use:

<?php
 $query = "SELECT GROUP_CONCAT(t.email) AS emails
             FROM YOUR_TABLE t"

 // Perform Query
 $result = mysql_query($query);

 while ($row = mysql_fetch_assoc($result)) {
    echo $row['emails'];
 }

 // Free the resources associated with the result set
 // This is done automatically at the end of the script
 mysql_free_result($result);
?>

References:

OMG Ponies