PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Fri Apr 12, 2013 11:47 am
i have a form that needs to be emailed and it as products attached to it. however i have a repeat region to list all the products but when i email it ithe email only shows the first item on the list.
below is the form set up
Code: Select all
//emailer
// Email new tenant information
$to = 'sales@domain.com';// . ',' . '$row_rsOrder["Email"]';
//$to = $row_rsOrder["Email"];
$subject = "Your Order Details";
$message = "
<html>
<head>
<title>Dear ".$row_rsOrder['FirstName'].$row_rsOrder['LastName']." please see your Order Details Below</title>
</head>
<body>
<img src=\"http://www.website.com/images/logoBLPP.jpg\" alt=\"" />
<h2>Your B Order".$row_rsOrder['OrderID']."</h2>
<table width='800' border='0' cellspacing='0' cellpadding='0'>
<tr><td><p>Thank you for shopping below are you details of the order you have recently placed. If you have any questions please contact us</p>
<br />
</a></p>
<tr><td></td></tr></table>
<table width='980' border='1' cellspacing='0' cellpadding='10'>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Customer Name</td>
<td class='text'>".$row_rsOrder['FirstName'] . $row_rsOrder['LastName']."</td>
<td bgcolor='#E9E9E9' class='header1'>Order ID</td>
<td bgcolor='#E9E9E9' class='text'>".$row_rsOrder['OrderID']."</td>
<td bgcolor='#E9E9E9' class='header1'>Order Status</td>
<td class='text'>".$row_rsOrder['TransactResult']."</td>
</tr>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Email</td>
<td class='text'>".$row_rsOrder['Email']."</td>
<td bgcolor='#E9E9E9' class='header1'> </td>
<td class='text'> </td>
<td bgcolor='#E9E9E9' ><span class='header1'>Order Date</span></td>
<td class='text'>".makeDateTime($row_rsOrder['OrderDate'], '%#d %B %Y', true)."</td>
</tr>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Shipping Address</td>
<td class='text'><p>".$row_rsOrder['Address']."</p>
<p>".$row_rsOrder['Town']."</p>
<p>".$row_rsOrder['PostCode']."</p>
<p>".$row_rsOrder['Country']."</p>
<p> </p></td>
<td> </td>
<td> </td>
<td colspan='2' align='right' valign='bottom'><span class='header'> ORDER TOTAL:".DoFormatCurrency($row_rsOrder['Total'], 2, ',', '.', '£ ', '')."<br />
</span><span class='text'>Shipping:".DoFormatCurrency($row_rsOrder['Shipping'], 2, ',', '.', '£ ', '')."</span><span class='header'><br />
</span></td>
</tr>
<tr valign='top'>
<td bgcolor='#E9E9E9' class='header1'>Product ID</td>
<td bgcolor='#E9E9E9' class='header1'>Product Description</td>
<td bgcolor='#E9E9E9' colspan='2' class='header1'>Size</td>
<td bgcolor='#E9E9E9' ><span class='header1'>Quantity</span></td>
<td bgcolor='#E9E9E9' align='right'><span class='header1'>Price</span></td>
</tr>
<?php do { ?>
<tr valign='top'>
<td class='text'>".$row_rsOrder['ProductID']."</td>
<td class='text'>".$row_rsOrder['Product'].','.$row_rsOrder['catname']."</td>
<td colspan='2' class='text'>".$row_rsOrder['UnitSize']."</td>
<td><span class='text'>".$row_rsOrder['Quantity']."</span></td>
<td align='right' class='text'>". DoFormatCurrency($row_rsOrder['UnitPrice'], 2, ',', '.', '£ ', '')."</td>
</tr>
<?php } while ($row_rsOrder = mysql_fetch_assoc($rsOrder)); ?>
<tr valign='top'>
<td class='text'> </td>
<td class='text'> </td>
<td colspan='2' class='text'> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: company name <email@domain.com>' . "\r\n";
$send = mail($to, $subject, $message, $headers);
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Fri Apr 12, 2013 2:33 pm
have you tried a while loop instead of the do-while loop?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Fri Apr 12, 2013 2:47 pm
have you tried a while loop instead of the do-while loop?
no how do i do that?
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Fri Apr 12, 2013 3:37 pm
Code: Select all
<?php while ($row_rsOrder = mysql_fetch_assoc($rsOrder)) { ?>
<tr valign='top'>
<td class='text'>".$row_rsOrder['ProductID']."</td>
<td class='text'>".$row_rsOrder['Product'].','.$row_rsOrder['catname']."</td>
<td colspan='2' class='text'>".$row_rsOrder['UnitSize']."</td>
<td><span class='text'>".$row_rsOrder['Quantity']."</span></td>
<td align='right' class='text'>". DoFormatCurrency($row_rsOrder['UnitPrice'], 2, ',', '.', '£ ', '')."</td>
</tr>
<?php } ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Fri Apr 12, 2013 3:45 pm
<?php while ($row_rsOrder = mysql_fetch_assoc($rsOrder)) { ?>
<tr valign='top'>
<td class='text'>".$row_rsOrder['ProductID']."</td>
<td class='text'>".$row_rsOrder['Product'].','.$row_rsOrder['catname']."</td>
<td colspan='2' class='text'>".$row_rsOrder['UnitSize']."</td>
<td><span class='text'>".$row_rsOrder['Quantity']."</span></td>
<td align='right' class='text'>". DoFormatCurrency($row_rsOrder['UnitPrice'], 2, ',', '.', '£ ', '')."</td>
</tr>
<?php } ?>
no that is still just showing the first order in the list
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Fri Apr 12, 2013 4:30 pm
where is the query that retrieves the data (where $rsOrder is created)?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Fri Apr 12, 2013 4:39 pm
here is the query
Code: Select all
$var1_rsOrder = "-1";
if (isset($_GET['OrderID'])) {
$var1_rsOrder = $_GET['OrderID'];
}
mysql_select_db($database_beau, $beau);
$query_rsOrder = sprintf("SELECT * FROM beauSS13_customers, beauSS13_orderdetails, beauSS13_orders, beauSS13_products, beauSS13_Stock, beauSS13_SizeList, beauSS13_Cat WHERE beauSS13_customers.CustomerID = beauSS13_orders.CustomerID AND beauSS13_orderdetails.ProductID = beauSS13_products.ProductID AND beauSS13_orderdetails.OrderID = beauSS13_orders.OrderID AND beauSS13_orderdetails.OrderID = %s AND beauSS13_orderdetails.StockID = beauSS13_Stock.StockID AND beauSS13_SizeList.SizeID = beauSS13_Stock.SizeID AND beauSS13_Cat.catID = beauSS13_products.CatID", GetSQLValueString($var1_rsOrder, "int"));
$rsOrder = mysql_query($query_rsOrder, $beau) or die(mysql_error());
$row_rsOrder = mysql_fetch_assoc($rsOrder);
$totalRows_rsOrder = mysql_num_rows($rsOrder);
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Fri Apr 12, 2013 5:32 pm
sorry, i should have phrased my question better: where on the page is that query located, same page, different page?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Jade
Forum Regular
Posts: 908 Joined: Sun Dec 29, 2002 5:40 pm
Location: VA
Post
by Jade » Fri Apr 12, 2013 5:42 pm
1) it's a problem with the data being stored on your products (ie some of them are missing order ID information)
2) it's a problem with how the query is joining the tables together. For instance you're looking for the product IDs to match but you're also looking for the stockIDs to match. What happens your products each have different stock IDs -- you only get the 1 product that matches the stock ID.
Your code for fetching the results looks okay. I would take your query into mysql and run it and see what results it's actually returning and go from there.
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Fri Apr 12, 2013 6:10 pm
sorry, i should have phrased my question better: where on the page is that query located, same page, different page?
the query is located at the top of the page above the email command
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Fri Apr 12, 2013 6:12 pm
Your code for fetching the results looks okay. I would take your query into mysql and run it and see what results it's actually returning and go from there.
on the same page i have the content of the email all set out and this looks fine with all the relevant information showing so all the query is working correct
so thats why i thought it was a problem with the way the products are being displayed in the repeat region
Jade
Forum Regular
Posts: 908 Joined: Sun Dec 29, 2002 5:40 pm
Location: VA
Post
by Jade » Sat Apr 13, 2013 5:48 pm
What happens if you do a var dump on the query results before the loop?
Code: Select all
<?php
$row_rsOrder = mysql_fetch_assoc($rsOrder);
var_dump($row_rsOrder);
while ($row_rsOrder = mysql_fetch_assoc($rsOrder)) { ?>
<tr valign='top'>
<td class='text'>".$row_rsOrder['ProductID']."</td>
<td class='text'>".$row_rsOrder['Product'].','.$row_rsOrder['catname']."</td>
<td colspan='2' class='text'>".$row_rsOrder['UnitSize']."</td>
<td><span class='text'>".$row_rsOrder['Quantity']."</span></td>
<td align='right' class='text'>". DoFormatCurrency($row_rsOrder['UnitPrice'], 2, ',', '.', '£ ', '')."</td>
</tr>
<?php } ?>
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Sun Apr 14, 2013 1:36 pm
What happens if you do a var dump on the query results before the loop?
it still emails just the first product in the repeat region
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Sun Apr 14, 2013 2:58 pm
Jade wrote: What happens if you do a var dump on the query results before the loop?
i think Jade means what results do you get from var_dump(); if there is just a single value inside there it would explain why just one item is being emailed
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Sun Apr 14, 2013 3:08 pm
Ok so do I need to do to fix this please