Re: email php function repeat region not working
Posted: Sun Apr 14, 2013 3:50 pm
try using mysql_fetch_array() instead of mysql_fetch_assoc()
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$row_rsOrder = mysql_fetch_assoc($rsOrder);
var_dump($row_rsOrder);
while ($row_rsOrder = mysql_fetch_array($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 } ?>Code: Select all
<?php
$row_rsOrder = mysql_fetch_array($rsOrder);
var_dump($row_rsOrder);
?>below is what is showing in the table. there are actually three items for this orderCan you paste the results of var_dump($rows_rsOrder)
now we know why only one set of values is being printedjonnyfortis wrote:Product ID Category Product Description Size Quantity Price
488 Jersey Shorts Storm Grey Triangle 2 years 1 £ 27,00
this is what i use for displaying the results in the brower ( which works )now we know why only one set of values is being printed
When displaying the results, do you also use mysql_fetch_assoc() ?
Code: Select all
<?php do { ?>
<tr valign="top">
<td class="text"><?php echo $row_rsOrder['ProductID']; ?></td>
<td class="text"><?php echo $row_rsOrder['catname']; ?></td>
<td class="text"><?php echo $row_rsOrder['Product']; ?></td>
<td colspan="2" class="text"><?php echo $row_rsOrder['UnitSize']; ?></td>
<td><span class="text"><?php echo $row_rsOrder['Quantity']; ?></span></td>
<td align="right" class="text"><?php echo DoFormatCurrency($row_rsOrder['UnitPrice'], 2, ',', '.', '£ ', ''); ?></td>
</tr>
<?php } while ($row_rsOrder = mysql_fetch_assoc($rsOrder)); ?> Code: Select all
<?php
$rsOrder = mysql_query($query_rsOrder, $beau) or die(mysql_error());
$row_rsOrder = mysql_fetch_assoc($rsOrder);
// add this
$orderData = $row_rsOrder;
$totalRows_rsOrder = mysql_num_rows($rsOrder);
// where you display the results in the email
// $orderData should contain the same data as $row_rsOrder
var_dump($orderData);
?>so i dont add <?php do { ?> and replace with your code?the code is in order so i'm not sure where the issue is; i can suggest an alternative that may or may not work. Since the display of the data is correct assign the variable with the data ($row_rsOrder) to another value and use that to create the data for the email.
If the var dump results of $orderData is the same as the values inside $row_rsOrder then you should be able to display the data in the email.
you'll still be using php code but now you will be using the array return by the innitial mysql_fetch_assoc() function;jonnyfortis wrote:so i dont add <?php do { ?> and replace with your code?
i have done the belowyou'll still be using php code but now you will be using the array return by the innitial mysql_fetch_assoc() function;
Code: Select all
<?php
$rsOrder = mysql_query($query_rsOrder, $beau) or die(mysql_error());
$row_rsOrder = mysql_fetch_assoc($rsOrder);
// add this
$orderData = $row_rsOrder;
$totalRows_rsOrder = mysql_num_rows($rsOrder);
while ($row_rsOrder = mysql_fetch_array($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>
var_dump($orderData);
?>Code: Select all
Notice: Undefined variable: orderData in E:\Domains\b\website.com\user\htdocs\admin\order-details-sent.php on line 137Code: Select all
Notice: Undefined variable: orderData in E:\Domains\b\website.com\user\htdocs\admin\order-details-sent.php on line 153Code: Select all
<?php
$rsOrder = mysql_query($query_rsOrder, $beau) or die(mysql_error());
$row_rsOrder = mysql_fetch_assoc($rsOrder);
// add this
$orderData = $row_rsOrder;
$totalRows_rsOrder = mysql_num_rows($rsOrder);
while ($row_rsOrder = mysql_fetch_array($rsOrder)) {
echo "
<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>";
var_dump($row_rsOrder);
?>
Code: Select all
Notice: Undefined variable: orderData in E:\Domains\b\website.com\user\htdocs\admin\order-details-sent.php on line 137
array(69) { ["CustomerID"]=> string(3) "132" ["LastName"]=> string(5) "test" ["FirstName"]=> string(5) "test" ["Contact"]=> NULL ["Position"]=> NULL ["Address"]=> string(21) "32 test" ["Town"]=> string(7) "test" ["County"]=> string(6) "test" ["PostCode"]=> string(7) "test" ["Country"]=> string(14) "United Kingdom" ["Telephone"]=> NULL ["Fax"]=> NULL ["Email"]=> string(21) "test@hotmail.com" ["Password"]=> string(12) "test" ["CardNumber"]=> NULL ["CardType"]=> NULL ["CardExpMonth"]=> NULL ["CardExpYear"]=> NULL ["Timestamp"]=> NULL ["Level"]=> string(5) "Guest" ["LogTracking"]=> string(1) "0" ["UniqueID"]=> string(3) "164" ["OrderID"]=> string(3) "789" ["ProductID"]=> string(3) "494" ["StockID"]=> string(3) "105" ["Color"]=> NULL ["UnitSize"]=> string(14) "18 - 24 months" ["UnitPrice"]=> string(2) "32" ["Quantity"]=> string(1) "1" ["Discount"]=> NULL ["Total"]=> string(5) "55.95" ["EmployeeID"]=> string(1) "0" ["OrderDate"]=> string(10) "2013-04-16" ["RequestDate"]=> NULL ["ShippingDate"]=> NULL ["Courier"]=> NULL ["Shipping"]=> string(4) "4.95" ["Tax"]=> string(1) "0" ["BillingCustomer"]=> NULL ["BillingAddress"]=> NULL ["BillingTown"]=> NULL ["BillingCounty"]=> NULL ["BillingPostCode"]=> NULL ["TransactResult"]=> string(9) "Completed" ["TransactID"]=> string(17) "4AS36871JB354070D" ["MsgNum"]=> NULL ["ResponseMsg"]=> string(0) "" ["Fulfilled"]=> string(1) "1" ["Cancelled"]=> NULL ["Product"]=> string(20) "test 11223" ["Producer"]=> string(3) "OEM" ["Description"]=> string(233) "test " ["Colors"]=> NULL ["Price"]=> string(5) "32.00" ["MinimumQty"]=> string(1) "0" ["QtyDiscountLimit"]=> NULL ["Stock"]=> string(1) "1" ["UnitWeight"]=> NULL ["Image"]=> string(29) "item.jpg" ["ImageDetail"]=> string(29) "image.jpg" ["CatID"]=> string(1) "9" ["Clearance"]=> string(0) "" ["ID"]=> string(3) "494" ["SizeID"]=> string(1) "3" ["sold"]=> string(1) "0" ["Size"]=> string(11) "6-12 months" ["catID"]=> string(1) "9" ["catImage"]=> string(43) "image.jpg" ["catname"]=> string(7) "Jumpers" } "; // 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: beauloves.co.uk ' . "\r\n"; $send = mail($to, $subject, $message, $headers); ?>Code: Select all
Notice: Undefined variable: orderData in E:\Domains\b\beauloves.co.uk\user\htdocs\admin\order-details-sent.php on line 137Code: Select all
<?php
$orderData = array(); // define $orderData, stop notice/s about the undefined variable
$rsOrder = mysql_query($query_rsOrder, $beau) or die(mysql_error());
$row_rsOrder = mysql_fetch_assoc($rsOrder);
// add this
$orderData = $row_rsOrder;
$totalRows_rsOrder = mysql_num_rows($rsOrder);
while ($row_rsOrder = mysql_fetch_array($rsOrder)) {
echo '
<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>';
var_dump($orderData); // <- we want to see what is inside this to determine whether it can be used or not
?>