Jump to content


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

  • Please log in to reply
1 reply to this topic

#1 bradkenyon

  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 25 September 2006 - 10:38 PM

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.

						// 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>";

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.

#2 trq

  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 September 2006 - 10:49 PM

$c = 1;
while($row = mysql_fetch_array( $result )) {
    if ($c == 1) {
      $emails = $row['email'];
    } else {
      $emails .= ', '.$row['email'];
echo "<input type=text value=\"$emails\">";

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users