Jump to content

[SOLVED] PHP Array from SQL Help


skylab001

Recommended Posts

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:

xxx@xxx.xxx, xxx@xxx.xxx, xxx@xxx.xxx, xxx@xxx.xxx, xxx@xxx.xxx

 

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
Share on other sites

<?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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.