Jump to content

[SOLVED] Repeating mysql rows and storing it in a string


jaikob

Recommended Posts

I am trying to create an invoice application that will send an invoice to a users email address.

I am using the php mail function.

 

I am successfully connected to mysql. What I want to do is repeat all rows returned, then store it in a string.

 

I would send an email like this:

 

<?php
$to = $row_loggedin['email'];
$subject = "Your Invoice For Order: ".$orderid;
$body = "This is where all of the html junk goes";
$headers = "The headers";
mail($to, $subject, $body, $headers);
?>

 

I have the $body set up with am html page with a table displaying the userrs quantity and product.

Currently it will send the invoice with only one row. I need to repeat all rows, then capture it in a string so I can send it.

 

I hope I made some sense.

for example:

 

 

id    product_id    temp_uuid    user_id    ordernum

 

Is how my orders table is structured. I usually Join my products and orders table together. my SQL filters temp_uuid out, and returns those rows as the products ordered.

 

I would format my string to be emailed like so:

 

$body = "this is some html, then i place this in a table: ".row['product_id']."this is some more html";

 

My general problem is that it will only send one row. I cannot loop inside of a string. I do not know how to achieve what I want. I could loop the variable, but that would just send multiple emails.

im a bit confused as to what your trying to do....are you;

 

a) trying to send out single e-mail to multiple clients with their unique individual invoices

 

b) trying to build the html for the invoice then sending it to a single client, then  (a). ?

 

///before this you connect and query the database for the certain user this might be put inside a loop
$body = "<table>";
while ($row = mysql_fetch_row($result)) 
{	
$body .= "<tr>";
$body .= "<td>";
$body .= $row[1];
$body .= "</td>";
$body .= "</tr>";

}; 
$body .="</table>";

$to = $some_one;
$subject = "Your Invoice For Order: ".$orderid;
$headers = "The headers";
mail($to, $subject, $body, $headers);


//close possible outer loop....and continue to next client....

 

 

hope that kinda makes some sence....

 

 

im a bit confused as to what your trying to do....are you;

 

a) trying to send out single e-mail to multiple clients with their unique individual invoices

 

b) trying to build the html for the invoice then sending it to a single client, then  (a). ?

 

///before this you connect and query the database for the certain user this might be put inside a loop
$body = "<table>";
while ($row = mysql_fetch_row($result)) 
{	
$body .= "<tr>";
$body .= "<td>";
$body .= $row[1];
$body .= "</td>";
$body .= "</tr>";

}; 
$body .="</table>";

$to = $some_one;
$subject = "Your Invoice For Order: ".$orderid;
$headers = "The headers";
mail($to, $subject, $body, $headers);


//close possible outer loop....and continue to next client....

 

 

hope that kinda makes some sence....

 

 

 

Thanks!! I got it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.