Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

E-mail database fields

Status
Not open for further replies.

iraad

Programmer
Joined
Apr 29, 2004
Messages
1
Location
NL
Hello,

I have a script to mail and it works, but there is a problem. I want to mail al the rows from the field, but now I only get one row from the field.

My script is:
-----------------------------

//SQL and database connection

$sql = "SELECT quiz_score.user_id, quiz_score.quiz_id
FROM quiz_score";

$db = new clsDBproeducation();
$db->query($sql);
unset($db);

//to and from
$to = "i.vanderraad@proeducation.nl";
$from = "Ivo van der Raad <raad@quicknet.nl>";

//subject
$subject = "Test mailing";

//message
$result = mysql_query($sql) OR die ("Query failed");
while ($row = mysql_fetch_assoc($result))
{
$message = $row["quiz_id"];
}//end loop

//headers
$headers = "From: $from\nReply-To: $from\nContent-type:text/html";

//mail
mail ($to, $subject, $message, $headers);

-----------------------------

When I end the loop after mail I get all the rows from field quiz_id but not in one E-mail but every row in an other e-mail.

How can I get all the fields in one e-mail?

Kind Regards,
Ivo van der Raad
 
Your line $message=$row["quiz_id"]; will only contain the last value in the loop as you simply assign a value to it. You need to do somrthing like:
set $message="" outside the loop
change $message=$row["quiz_id"] to $message=$message . $row["quiz_id"];

That should set you on your way
 
You might want to delineate the lines somehow, unless the records themselves contain newline characters.
You could collect all the info in an array and then implde it:
Code:
while ($row = mysql_fetch_assoc($result)){
   $message[] = $row['whatevercolumn'];
}
# now implode all with a newline
$messageText = implode("\n",$message);
Or you can just concatenate it the way ingresman said but add the newline.
Code:
$message .= "\n".$row['whatevercolumn'];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top