skylab001 Posted October 24, 2007 Share Posted October 24, 2007 I'm a total newbie at this, and still trying to get my head around the basics. I have bought a few books to help me learn but they just don't explain everything. I have started to just write very basic scripts as I'm learning. I have been trying to write a script that will pull email addresses from my website SQL database and display them as an array on a page. I would like it to display like this: [email protected], [email protected], [email protected], [email protected], [email protected] The emails are in a table called "test" and they have a status of 'approved' or 'declined' I want to select only the emails that are 'approved'. So far my script works about 50%. The problem is that it only seems to pull 1 email address rather than all of them. maybe somebody can tell me why this is? here is my code: <?php include "../database.php"; $query = "SELECT * FROM Test WHERE Status = 'Approved'"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $email_list = $row['Emails']; } echo $email_list; ?> I've been pulling my hair out trying to get this to work so it's time I ask for help Thanks for any that can be spared. Brian Link to comment https://forums.phpfreaks.com/topic/74527-solved-php-array-from-sql-help/ Share on other sites More sharing options...
teng84 Posted October 24, 2007 Share Posted October 24, 2007 $email_list = $row['Emails']; <--wrong if you want more email maybe $email_list .= $row['Emails']; <---concatenate or $email_list[] = $row['Emails'];<--store in array Link to comment https://forums.phpfreaks.com/topic/74527-solved-php-array-from-sql-help/#findComment-376667 Share on other sites More sharing options...
trq Posted October 24, 2007 Share Posted October 24, 2007 <?php include "../database.php"; $query = "SELECT * FROM Test WHERE Status = 'Approved'"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $email_list[] = $row['Emails']; } echo implode(',',$email_list); ?> Link to comment https://forums.phpfreaks.com/topic/74527-solved-php-array-from-sql-help/#findComment-376670 Share on other sites More sharing options...
skylab001 Posted October 24, 2007 Author Share Posted October 24, 2007 Thanks works now, see that I was missing the Implode Link to comment https://forums.phpfreaks.com/topic/74527-solved-php-array-from-sql-help/#findComment-376690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.