I have 50 members in a a database, and I want to comma delimit them... so I use: $fetch = mysql_query("SELECT email FROM members"); $data = mysql_fetch_array($fetch); $delimited = implode(", ", $data); Code (markup): However it just shows the first entry twoce like: email1, email1 so if I use $fetch = mysql_query("SELECT email FROM members"); $data = mysql_fetch_array($fetch, MYSQL_ASSOC); $delimited = implode(", ", $data); Code (markup): then it just displays email1 How can I get it to comma delimit all emails?
You have to loop over the results. $emails = array(); $fetch = mysql_query("SELECT email FROM members"); while ($data = mysql_fetch_array($fetch)) { array_push($data['email'], $emails); } $delimited = implode(", ", $emails); PHP:
You need to run through the result set: $fetch = mysql_query("SELECT email FROM members"); while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) { $emails[] = $row['email']; } $delimited = implode(", ", $emails); PHP: HTH, cheers!
Yeah, right there you're only telling it to grab the first result . The code above is the stuff you want to use. Also, to remove the trailing comma, add this: $delimited = substr($delimited, 0, strlen($delimited) - 2); PHP: All set