Jump to content

Archived

This topic is now archived and is closed to further replies.

bradkenyon

[SOLVED] pulling email field out of database table into email to: field

Recommended Posts

I have a simple table setup, which I have 2 or 3 email addresses stored in the one field table, table titled email, and field titled email.

I want to pull the emails from the table and put it in a input type box, as its value.

For example: <input type="text" name="to" value="$email">

I don't know exactly how do this, currently I have it going into the text box, like explained above, but it is outputting a different text box for each email. I just want it all in the same text box, example:

joe@joe.com, brad@brad.com, george@gmail.com

This would be what I want, just like you would send an email to multiple people, separating the different emails by commas in the "to:" field of an email.

[code]
<?php
// Make a MySQL Connection
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

// Get all the data from the "email" table
$result = mysql_query("SELECT * FROM email")
or die(mysql_error()); 

echo "<table border='1'>";
echo "<tr> <th>Email</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<input type=text value=$row[email]>";
}

echo "</table>";
?>
[/code]

This is what I have currently, which will output a text box for each email, instead of that, I just want one text box, with all the emails in it, separated by commas.

Thanks in advanced.

Share this post


Link to post
Share on other sites
[code=php:0]
$c = 1;
while($row = mysql_fetch_array( $result )) {
    if ($c == 1) {
      $emails = $row['email'];
    } else {
      $emails .= ', '.$row['email'];
    }
    $c++;
}
echo "<input type=text value=\"$emails\">";
[/code]

Share this post


Link to post
Share on other sites

×

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.