SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mail() db contents from while loop

    I'm having this issue with the mail() function where I want to list the contents of a particular table row for row. Problem is that I can only get it to output either only 1 row, or send an email for each row.

    Here's what I have (this way sends 1 message but only 1 row... 'cuz the mail() is outside the loop):

    PHP Code:
    $result mysql_query("SELECT name, fee from db;");
    while(
    $row mysql_fetch_array($result)) {
        
    extract($row);

    $comment="name: $name - fee: $$fee";

    }
    $subject "Monthly Summary List";
    $fromName $yourname;
    $fromAddres $youremail;
    $to "me@domain.net";

    mail($to$subject$comment"From: ".$fromName." <".$fromAddress.">");

    I'd like to display in the following format but my beginner's php skills don't cut it:

    name: fred - fee: $9.00
    name: joe - fee: $20.00
    name: bill - fee: $3.00
    Total: $32.00

    thanks for the continuing support!
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  2. #2
    SitePoint Zealot Paul_M's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    try changing this line:
    $comment="name: $name - fee: $$fee";

    to this line:
    $comment .= "name: $name - fee: $$fee \n";

    notice the .= and the \nat the end of the line.

    Tell me if it works :-)

  3. #3
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah... sweet. Just needed a coupe minor modifications. Thanks.

    To add up the $fee's from the rows in the while loop, do I put something like $fee++ inside the loop?

    thanks for your help!
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  4. #4
    SitePoint Zealot Paul_M's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    you could use another variable like $totalfee...initialize it to 0 outside the loop

    then just do $totalfee += $fee;

    :-)

  5. #5
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great!! It works perfectly.

    Thanks again!
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •