Jump to content

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


bradkenyon

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.
Link to comment
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]
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.