Page 1 of 3

email php function repeat region not working

Posted: Fri Apr 12, 2013 11:47 am
by jonnyfortis
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'>&nbsp;</td>
        <td class='text'>&nbsp;</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>&nbsp;</p></td>
        <td>&nbsp;</td>
        <td>&nbsp;</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'>&nbsp;</td>
        <td class='text'>&nbsp;</td>
        <td colspan='2' class='text'>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</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);

Re: email php function repeat region not working

Posted: Fri Apr 12, 2013 2:33 pm
by social_experiment
have you tried a while loop instead of the do-while loop?

Re: email php function repeat region not working

Posted: Fri Apr 12, 2013 2:47 pm
by jonnyfortis
have you tried a while loop instead of the do-while loop?
no how do i do that?

Re: email php function repeat region not working

Posted: Fri Apr 12, 2013 3:37 pm
by social_experiment

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 }  ?>

Re: email php function repeat region not working

Posted: Fri Apr 12, 2013 3:45 pm
by jonnyfortis
<?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

Re: email php function repeat region not working

Posted: Fri Apr 12, 2013 4:30 pm
by social_experiment
where is the query that retrieves the data (where $rsOrder is created)?

Re: email php function repeat region not working

Posted: Fri Apr 12, 2013 4:39 pm
by jonnyfortis
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);

Re: email php function repeat region not working

Posted: Fri Apr 12, 2013 5:32 pm
by social_experiment
sorry, i should have phrased my question better: where on the page is that query located, same page, different page?

Re: email php function repeat region not working

Posted: Fri Apr 12, 2013 5:42 pm
by Jade
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.

Re: email php function repeat region not working

Posted: Fri Apr 12, 2013 6:10 pm
by jonnyfortis
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

Re: email php function repeat region not working

Posted: Fri Apr 12, 2013 6:12 pm
by jonnyfortis
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

Re: email php function repeat region not working

Posted: Sat Apr 13, 2013 5:48 pm
by Jade
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 }  ?>

Re: email php function repeat region not working

Posted: Sun Apr 14, 2013 1:36 pm
by jonnyfortis
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

Re: email php function repeat region not working

Posted: Sun Apr 14, 2013 2:58 pm
by social_experiment
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

Re: email php function repeat region not working

Posted: Sun Apr 14, 2013 3:08 pm
by jonnyfortis
Ok so do I need to do to fix this please