Jump to content


Photo

Inserting multiple entries in email


  • Please log in to reply
2 replies to this topic

#1 DLR

DLR
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationJohannesburg, South Africa

Posted 27 June 2006 - 01:13 PM

Hi all.

I have a database with a lst of birthdays and have written a script to access the database on a daily basis. If there are any birthdays that day, it inserts the name from the database into the script and sends of an email to wish that person a happy birthday.

If there is more than one person with a birthday on that day, it will send a separate email to each person having a birthday.

Instead of just copying this letter(s) to me, I would like the script to send me one email with a list of the people having a birthday that day.

I have tried to use an array, but do not seem to be able to get this to work - I get "resource#4" or something like that , in the email.

My email script goes like this:

$check_birthdays = "SELECT * FROM birthdays WHERE day = $today_day AND month = $today_month";
$result = mysql_query($check_birthdays) or die(mysql_error());

if (mysql_num_rows($result) >> 0 ) {

//send email to each person who has a birthday today
while ($row = mysql_fetch_array($result)) {
extract($row);
birthday_wishes(); // this is a function to insert the data from the table
and send off the email - works fine
}
// send one email with list of all people having birthday today
birthday_list()

function birthday_list() {
global $row;
$to = "me";
$from = "server";
$subject2 = "Today's birthday list";
$messagebody2 = "The following clients have birthdays today, " . date('d/F/Y') . " <p> " . print_r($result);



#2 Wildbug

Wildbug
  • Members
  • PipPipPip
  • Advanced Member
  • 1,149 posts

Posted 27 June 2006 - 02:38 PM


1. Why are you using a bit-shift?
if (mysql_num_rows($result) >> 0 ) {
2. Why don't you just compose a string to yourself while you loop through the results?
$text_to_myself = 'The following clients have birthdays today, ' . date('d/F/Y') . '<p>';
while ($row = mysql_fetch_array($result)) {
    // ....  I don't know what your rows are called, but...
    $text_to_myself .= "$row[firstname] $row[lastname] ($row[age])<br>\n";
    // ....
}
$text_to_myself .= '</p>';
// send it.

If you're getting something like "resource#4", then you're probably trying to print the MySQL resource handle directly somehow.
Twice a day my clock works PERFECTLY!  I can't figure out what's wrong with it.

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 July 2006 - 02:07 AM

Well, you'd have to use mysql_fetch_assoc to get the hash back; also, any attempt to print $result directly is the source of your "resource #N" output.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users