?
Solved

Assigning Variables to Dynamic Data

Posted on 2009-04-30
4
Medium Priority
?
182 Views
Last Modified: 2012-05-06
I have a page written in PHP.  It fetches data from a table.  Sometimes, there are rows that have the same orderID.  One OrderID may have multiple rows of data.  For example... for each orderID there is a Name, SKU #, and Quantity.  So in my database(mysql) there is two rows with the same OrderID.

ID    Name          SKU          Quantity
48   Item1           44/83        1
48   Item2           9953         5

So using a do while loop, I can pull the information from the database just fine.  Here is my problem.  I need to place the ID, Name, SKU, and Quantity results in variables so I can use them for sendmail.  So as I have it now, I choose a customer, and I have their order ID, Name, SKU, and Quantity listed on my page.  I need to setup a form to click where this information can be emailed.  I can handle this part but how do I place the data into variables?  Is this variables on the fly, and array or what.  thanks

Below is my do while loop.
<?php do { ?>
     <tr>
       <td><?php echo $row_rsOrderDetails['DetailOrderID']; ?></td>
       <td><?php echo $row_rsOrderDetails['DetailItemName']; ?></td>
       <td><?php echo $row_rsOrderDetails['ItemSKU']; ?></td>
       <td><?php echo $row_rsOrderDetails['ItemKey']; ?></td>
       <td><?php echo $row_rsOrderDetails['DetailQuantity']; ?></td>
     </tr>
     <?php } while ($row_rsOrderDetails = mysql_fetch_assoc($rsOrderDetails)); ?>

Open in new window

0
Comment
Question by:rbudj
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:EMB01
ID: 24274025
If you need to send the variables in an email, you'll want to do as attached. Let me know how it works out.
<?php 
 
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
 
// put all the rows of HTML into the body variable
do { 
$body .= <tr>
$body .=       <td><?php echo $row_rsOrderDetails['DetailOrderID']; ?></td>
$body .=       <td><?php echo $row_rsOrderDetails['DetailItemName']; ?></td>
$body .=       <td><?php echo $row_rsOrderDetails['ItemSKU']; ?></td>
$body .=       <td><?php echo $row_rsOrderDetails['ItemKey']; ?></td>
$body .=       <td><?php echo $row_rsOrderDetails['DetailQuantity']; ?></td>
$body .= </tr>
} while ($row_rsOrderDetails = mysql_fetch_assoc($rsOrderDetails)); 
 
// mail the contents
mail('email@website.com', $body, $headers);
 
?>

Open in new window

0
 
LVL 16

Author Comment

by:rbudj
ID: 24314065
im still working on this... will report back
0
 
LVL 14

Accepted Solution

by:
EMB01 earned 1500 total points
ID: 24315168
Hey, I wanted to make a quick adjustment by putting the contents of $body in quotations for better syntax. I concatenized the variables instead of whatever I had before...
<?php 
 
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
 
// put all the rows of HTML into the body variable
do { 
$body .= "<tr>";
$body .= "      <td>".$row_rsOrderDetails['DetailOrderID']."</td>";
$body .= "      <td>".$row_rsOrderDetails['DetailItemName']."</td>";
$body .= "      <td>".$row_rsOrderDetails['ItemSKU']."</td>";
$body .= "      <td>".$row_rsOrderDetails['ItemKey']."</td>";
$body .= "      <td>".$row_rsOrderDetails['DetailQuantity']."</td>";
$body .= "</tr>";
} while ($row_rsOrderDetails = mysql_fetch_assoc($rsOrderDetails)); 
 
// mail the contents
mail('email@website.com', $body, $headers);
 
?>

Open in new window

0
 
LVL 16

Author Closing Comment

by:rbudj
ID: 31576537
thank you
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question