Forum Moderators: coopster
foreach($order_qty as $id_no => $val) {
$detailqry2 = "SELECT * FROM misc_order_detail, misc_order_items WHERE misc_order_detail.order_no = '".$order_no."' AND misc_order_items.id_no = '".$id_no."'";
$result2=mysql_query($detailqry2, $conn);
while ($row=mysql_fetch_array($result2, $conn)) {
$description=$row["description"];
$vpc=$row["vpc"];
$min=$row["min"];
$max=$row["max"];
$order_qty2=$row["order_qty"];
$message .= '
<TR>
<TD>".$description."</TD>
<TD>".$vpc."</TD>
<TD><center>".min."</center></TD>
<TD><center>".$max."</center></TD>
<TD><center>".$package_qty."</center></TD>
<TD><center>".$order_qty2."</center></TD>
</TR>
';
}
}
The output just looks like this:
Description
VPC
Min
Max
Pkge Qty
Order
".$description."
".$vpc."
".min."
".$max."
".$package_qty."
".$order_qty2."
".$description."
".$vpc."
".min."
".$max."
".$package_qty."
".$order_qty2."
Thanks for the help.
<?
foreach($order_qty as $id_no => $val) {
$detailqry2 = "SELECT * FROM misc_order_detail, misc_order_items WHERE misc_order_detail.order_no = '".$order_no."' AND misc_order_items.id_no = '".$id_no."'";
$result2=mysql_query($detailqry2, $conn);
while ($row=mysql_fetch_array($result2, $conn)) {
$description=$row['description'];
$vpc=$row['vpc'];
$min=$row['min'];
$max=$row['max'];
$order_qty2=$row['order_qty'];
?>
<TR>
<TD><?=$description?></TD>
<TD><?=$vpc?></TD>
<TD><center><?=min?></center></TD>
<TD><center><?=$max?></center></TD>
<TD><center><?=$package_qty?></center></TD>
<TD><center><?=$order_qty2?></center></TD>
</TR>
<?
}
}
?>
I have three databases set up. The first one, called misc_order_items, is a list of items available to order via a web page. The web page goes through each item in the database and lists them out in a table. The order column is set up as an array. Once they hit submit, the header data (store number, date, and order number) is stored in a database I call misc_order_header. Once that INSERT takes place, I have a foreach statement and I insert each line of the order, currently there are 16 items, into a detail database. That database is called misc_order_detail. The detail line has the same $id_no as the items database to make sure that I can always refer back to the original item.
In the script above, after I have inserted all of the data into the three databases I am trying to send out an e-mail with the data. That is where this script comes into play, but I am not doing the select or fetch correctly. Here is the complete mail script:
// send the mail
// recipients
$to = "Jeff Grossman <****@****.com>";
// subject
$subject = "Weekly Store Order";
// from
// from data snipped!
// message
$message = "
<HTML>
<HEAD>
<TITLE>Weekly Store Order</TITLE>
</HEAD>
<BODY>
Weekly Store Order - Store: {$store}<BR><BR>
<TABLE>
<TR>
<TD width=\"250\"><center><b><u>Description</u></b></center></TD>
<TD width=\"60\"><center><b><u>VPC</u></b></center></TD>
<TD width=\"60\"><center><b><u>Min</u></b></center></TD>
<TD width=\"60\"><center><b><u>Max</u></b></center></TD>
<TD width=\"80\"><center><b><u>Pkge Qty</u></b></center></TD>
<TD width=\"60\"><center><b><u>Order</u></b></center></TD>
</TR>
";
foreach($order_qty as $id_no => $val) {
$detailqry2 = "SELECT * FROM misc_order_detail, misc_order_items WHERE misc_order_detail.order_no = '".$order_no."' AND misc_order_items.id_no = '".$id_no."'";
$result2=mysql_query($detailqry2, $conn);
while ($row=mysql_fetch_array($result2, $conn)) {
$description=$row["description"];
$vpc=$row["vpc"];
$min=$row["min"];
$max=$row["max"];
$order_qty2=$row["order_qty"];
$message .= "
<TR>
<TD>{$description}</TD>
<TD>{$vpc}</TD>
<TD><center>{$min}</center></TD>
<TD><center>{$max}</center></TD>
<TD><center>{$package_qty}</center></TD>
<TD><center>{$order_qty2}</center></TD>
</TR>
";
}
}
$message .= "
<TR>
<TD> </TD>
</TR>
<TR>
<TD colspan=\"6\"><textarea rows=\"5\" cols=\"80\" name=\"comment\" wrap>{$comment}</textarea></TD>
</TR>
</TABLE>
</BODY>
</HTML>
";
//To send HTML mail, you can set the Content-type header.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
//additional headers
$headers .= "To: {$to}\r\n";
$headers .= "From: {$from}\r\n";
//and now mail it
mail($to, $subject, $message, $headers);
The correct data is in the database, I can't seem to get it out correctly. Here is the output from the mail command:
Weekly Store Order - Store: 09
Description
VPC
Min
Max
Pkge Qty
Order
4473's
{min}
2
9
4473's
{min}
2
8
<same repeated many times>
Bank Deposit Bags
{min}
100
9
Bank Deposit Bags
{min}
100
8
<same repeated many times>
I snipped it. But, it appears to be listing the same item 16 times, instead of each item just once.
Thanks again for your help.
[edited by: jatar_k at 7:58 pm (utc) on Aug. 5, 2004]
[edit reason] snipped repetitive code [/edit]
I want to cycle through the detail database and find each occurance of the same order_no. Then go through those items and find the respective id_no in the items database that goes with that particular line in the detail database.
Is my SELECT statement incorrect?
$detailqry2 = "SELECT * FROM misc_order_detail WHERE order_no = '".$order_no."'";
$result2=mysql_query($detailqry2, $conn);
while ($row=mysql_fetch_array($result2, $conn)) {
$order_no2=$row["order_no"];
$id_no=$row["id_no"];
$sku=$row["sku"];
$order_qty2=$row["order_qty"];
$order_date=$row["order_date"];
$store2=$row["store"];
$detailqry3 = "SELECT * FROM misc_order_items WHERE id_no = '".$id_no."'";
$result3=mysql_query($detailqry3, $conn);
while ($row=mysql_fetch_array($result3, $conn)) {
$id_no=$row["id_no"];
$sku=$row["sku"];
$description=$row["description"];
$vpc=$row["vpc"];
$package_qty=$row["package_qty"];
$location=$row["location"];
$min=$row["min"];
$max=$row["max"];
$message .= "
<TR>
<TD>{$description}</TD>
<TD>{$vpc}</TD>
<TD><center>{$min}</center></TD>
<TD><center>{$max}</center></TD>
<TD><center>{$package_qty}</center></TD>
<TD><center>{$order_qty2}</center></TD>
</TR>
";
}
mysql_free_result($result3);
}
mysql_free_result($result2);