Jump to content

Combine rows together in one email instead of single emails


ScreanerHS

Recommended Posts

Hello guys,

I'm new to this board. I just signed up because I have a issue with something I can't get to work. I really don't know how to handle it. I hope someone with amazing PHP skills can help me out. I trust one you guys :)

Ok, I made a script with orders in it from our customers. That placed a order, and the database will be filled. A script show the rows from a database. Every row has a checkbox in front of the row. When you select the checkbox and press submit that specified row will disappear from the list and a automatic email has been sent to the customer that his/her order has been shipped. Everything works fine. The script sends a email and a text message to the customer.

Well, sometimes a customer orders 2 or more things. Now the customers get 2 or 3 emails and text message that their products are send out. I want to combine the products in 1 email. So instead of 3 separated emails, I only want the script to send out 1 with all 3 products in it. If a customer only has one product, the script has just to send out a email with 1 product inside.

The "wpos" value is the order number, so i need something that check for the "wpos" value and combine all together in 1 email. Do you think something like this is possible? I'm busy to think of a way for 1.5 week now till deep in the night but can't get it to work.

Here is my PHP code.

<?php

include 'mysql.php';

if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox'];
if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"])
$id = "('" . implode( "','", $checkbox ) . "');" ;
$sql="UPDATE table_name SET closed = '".(isset($activate)?'yes':'no')."' WHERE id IN $id" ;
$result = mysql_query($sql) or die(mysql_error());

$sql="SELECT * FROM table_name WHERE closed='yes' AND id IN $id";
$result=mysql_query($sql);

$count2=mysql_num_rows($result);
while($rows=mysql_fetch_array($result)){

//////////
// script for sending out mime emails and text messages on cellphone taken out
// using $rows[values] for reading the database
//////////

}

$sql="SELECT * FROM table_name WHERE closed = 'no' AND handled = 'yes' ORDER BY wpos ASC";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Openstaande web orders</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="smartDark.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="pragma" content="no-cache" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="javascript/jquery.toastmessage.js" type="text/javascript"></script>
<link href="resources/css/jquery.toastmessage.css" rel="stylesheet" type="text/css" />


<script type="text/javascript">
<!--
function un_check(){
for (var i = 0; i < document.frmactive.elements.length; i++) {
var e = document.frmactive.elements[i];
if ((e.name != 'allbox') && (e.type == 'checkbox')) {
e.checked = document.frmactive.allbox.checked;
}}}
//-->
</script>

<body>
<form name="frmactive" method="post" action="">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td>
<table border="0" cellpadding="4" cellspacing="1" class="forumline" align="center" width="1380" height="50">
<tr>
<td colspan="2" class="catBottom" nowrap="nowrap" align="left" valign="center"> <span class="postbody"><font color="#9A9999"><b>Locatie: <i>Verstuur Ontvangstbevestiging - <?php echo $filiaal ?></b></i></font></span></td>
</tr>
</table>

<table cellpadding="4" cellspacing="1" width="650"  align="center">
<td class="row2" width="130" align="right" valign="top"></td>
<td width="644" class="row2"><span class="postbody" valign="top" align="left"> </td>
</span></td>
</table>

<table cellpadding="4" cellspacing="1" class="forumline" align="center" >
<td class="row2" width="23" align="center" valign="middle"><span class="postbody"><input type="checkbox" name="allbox" title="Select of Deselect alles" onclick="un_check()";/></span></td>
<td class="row2" width="55" align="center" valign="middle"><span class="postbody"><b>BRAM</b></span></td>
<td class="row2" width="55" align="center" valign="middle"><span class="postbody"><b>WPOS</b></span></td>
<td class="row2" width="135" align="center" valign="middle"><span class="postbody"><b>Order Datum / Tijd</b></span></td>
<td class="row2" width="370" align="left" valign="middle"> <span class="postbody"><b>Artikel Omschrijving</b></span></td>
<td class="row2" width="20" align="center" valign="middle"> <span class="postbody"><b>#</b></span></td>
<td class="row2" width="300" align="left" valign="middle"> <span class="postbody"><b>Klant Naam / Bedrijfsnaam</b></span></td>
<td class="row2" width="90" align="left" valign="middle"> <span class="postbody"><b>Mobiel</b></span></td>
<td class="row2" width="250" align="left" valign="middle"> <span class="postbody"><b>E-Mail adres</b></span></td>
</table>

<?php
while($rows=mysql_fetch_array($result)){
?>

<table cellpadding="4" cellspacing="1" class="forumline" align="center">
<td class="row2" width="23" align="center" valign="middle"><span class="postbody"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></span></td>
<td class="row2" width="55" align="center" valign="middle"><span class="postbody"><?php echo $rows[bram] ?></span></td>
<td class="row2" width="55" align="center" valign="middle"><span class="postbody"><?php echo $rows[wpos] ?></span></td>
<td class="row2" width="135" align="center" valign="middle"><span class="postbody"><?php echo $rows[aanmaaktijd] ?></span></td>
<td class="row2" width="370" align="left" valign="middle"> <span class="postbody">[<?php echo $rows[custom_item_nummer] ?>] <?php echo $rows[beschrijving] ?></span></td>
<td class="row2" width="20" align="center" valign="middle"><span class="postbody"><?php echo $rows[aantal] ?></span></td>
<td class="row2" width="300" align="left" valign="middle"> <span class="postbody"><?php echo $rows[klant_naam] ?></span></td>
<td class="row2" width="90" align="left" valign="middle"> <span class="postbody"><?php echo $rows[mobiel_nummer] ?></span></td>
<td class="row2" width="250" align="left" valign="middle"> <span class="postbody"><?php echo $rows[klant_email] ?></span></td>
</table>

<?php } ?>

</form>
<br><br>

<table border="0" cellpadding="4" cellspacing="1" align="center" width="1380">
<tr>
<td colspan="1" nowrap="nowrap" align="left" valign="center"> <span class="postbody"><input name="activate" type="submit" id="activate" value="Send notification" />  <input name="deactivate" type="submit" id="deactivate" value="remove order" onclick="return confirm('are you sure you want to remove the order?')"/></span></td>
</tr>
</table>


<?php

}

else{

header('Location: http://website.com/index.php');

}

?>

Hope someone can help me out. If you have questions, please let me know!
Thanks in advanced!

Marco Pavone

Link to comment
Share on other sites

Way too much code to wade through!

 

But - it appears that you are trying (?) to create an html-style email message using a table to display the pertinent information.  Fine.

Start your html table before your results processing loop. After that code use your loop to grab each row of data, create a new row of your table.  Once the loop is over, write out the html to close the table and finish the body of your email.

 

Basically:

 

$msgbody = (introductory message);

// start table

$msgbody .= "<table><tr><th>xxxx</th><th>yyyyy</th><th>zzzzz</th></tr>";

//  begin the loop

while ($row = xxx)

{

   $msgbody .= "<tr><td>$row['abc']</td><td>$row['def']</td><td>$row['ghi']</td></tr>";

}

// end the table

$msgbody.= "</table>";

 

Am I close?

Link to comment
Share on other sites

Hi ginerjm,

 

I can't get it to work :(

Here is my full code including the HTML mail script i use. Hopefully you can help me out. I really don't see it anymore :(

 

Thnx in advance

<?php

include("include/session.php");
include 'mysql.php';

/**
 * User has already logged in, so display relavent links, including
 * a link to the admin center if the user is an administrator.
 */
if($session->logged_in){

$q = mysql_query("SELECT * FROM MycomDHA_FILIALEN WHERE filiaal = '$session->username'") or die(mysql_error());
while($row = mysql_fetch_array($q))
{
extract($row);
}


require('classes/class.mollie.php');
require_once('Mail.php');
require_once('Mail/mime.php');

if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox'];
if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"])
$id = "('" . implode( "','", $checkbox ) . "');" ;
$sql="UPDATE table SET afgerond = '".(isset($activate)?'Ja':'Weg')."' WHERE id IN $id" ;
$result = mysql_query($sql) or die(mysql_error());

$datum_tijd_afmelden = date( "d-m-Y G:i" );

$sql="SELECT * FROM table WHERE afgerond='Ja' AND id IN $id";
$result=mysql_query($sql);

$count2=mysql_num_rows($result);
while($rows=mysql_fetch_array($result)){

$to = "$rows[klant_email]";
$from = "sender";
$subject = "subject";

// email header format complies the PEAR's Mail class
// this header includes sender's email and subject
$headers = array('From' => $from,
'Subject' => $subject);

$htmlMessage = <<<PDFMAIL

////////////<MY HTML CODE with $rows[custom_item_nummer], $rows[amount], $rows[description] etc>

<<<PDFMAIL

$mime = new Mail_Mime();
$mime->setHtmlBody($htmlMessage);

// build email message and save it in $body
$body = $mime->get();

// build header
$hdrs = $mime->headers($headers);

// create Mail instance that will be used to send email later
$mail = &Mail::factory('mail');

// Sending the email, according to the address in $to,
// the email headers in $hdrs,
// and the message body in $body.
$mail->send($to, $hdrs, $body);


}

}

$sql="SELECT * FROM table WHERE afgerond = 'Nee' AND behandeld = 'Ja' ORDER BY wpos ASC";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Openstaande web orders</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="smartDark.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="pragma" content="no-cache" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script type="text/javascript">
<!--
function un_check(){
for (var i = 0; i < document.frmactive.elements.length; i++) {
var e = document.frmactive.elements[i];
if ((e.name != 'allbox') && (e.type == 'checkbox')) {
e.checked = document.frmactive.allbox.checked;
}}}
//-->
</script>

<body>
<form name="frmactive" method="post" action="">
<p align="center"><a href='http://mycomwebbestellingen.nl/index.php'><img src='http://mycomwebbestellingen.nl/images/mycom_webbestellingen.png' /></a></p>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td>
<table border="0" cellpadding="4" cellspacing="1" class="forumline" align="center" width="1380" height="50">
<tr>
<td colspan="2" class="catBottom" nowrap="nowrap" align="left" valign="center"> <span class="postbody"><font color="#9A9999"><b>Locatie: <i>Verstuur Ontvangstbevestiging - <?php echo $filiaal ?></b></i></font></span></td>
</tr>
</table>

<table cellpadding="4" cellspacing="1" width="650"  align="center">
<td class="row2" width="130" align="right" valign="top"></td>
<td width="644" class="row2"><span class="postbody" valign="top" align="left"> </td>
</span></td>
</table>

<table cellpadding="4" cellspacing="1" class="forumline" align="center" >
<td class="row2" width="23" align="center" valign="middle"><span class="postbody"><input type="checkbox" name="allbox" title="Select of Deselect alles" onclick="un_check()";/></span></td>
<td class="row2" width="55" align="center" valign="middle"><span class="postbody"><b>BRAM</b></span></td>
<td class="row2" width="55" align="center" valign="middle"><span class="postbody"><b>WPOS</b></span></td>
<td class="row2" width="135" align="center" valign="middle"><span class="postbody"><b>Order Datum / Tijd</b></span></td>
<td class="row2" width="370" align="left" valign="middle"> <span class="postbody"><b>Artikel Omschrijving</b></span></td>
<td class="row2" width="20" align="center" valign="middle"> <span class="postbody"><b>#</b></span></td>
<td class="row2" width="300" align="left" valign="middle"> <span class="postbody"><b>Klant Naam / Bedrijfsnaam</b></span></td>
<td class="row2" width="90" align="left" valign="middle"> <span class="postbody"><b>Mobiel</b></span></td>
<td class="row2" width="250" align="left" valign="middle"> <span class="postbody"><b>E-Mail adres</b></span></td>
</table>

<?php
while($rows=mysql_fetch_array($result)){
?>

<table cellpadding="4" cellspacing="1" class="forumline" align="center">
<td class="row2" width="23" align="center" valign="middle"><span class="postbody"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></span></td>
<td class="row2" width="55" align="center" valign="middle"><span class="postbody"><?php echo $rows[bram] ?></span></td>
<td class="row2" width="55" align="center" valign="middle"><span class="postbody"><?php echo $rows[wpos] ?></span></td>
<td class="row2" width="135" align="center" valign="middle"><span class="postbody"><?php echo $rows[aanmaaktijd] ?></span></td>
<td class="row2" width="370" align="left" valign="middle"> <span class="postbody">[<?php echo $rows[custom_item_nummer] ?>] <?php echo $rows[beschrijving] ?></span></td>
<td class="row2" width="20" align="center" valign="middle"><span class="postbody"><?php echo $rows[aantal] ?></span></td>
<td class="row2" width="300" align="left" valign="middle"> <span class="postbody"><?php echo $rows[klant_naam] ?></span></td>
<td class="row2" width="90" align="left" valign="middle"> <span class="postbody"><?php echo $rows[mobiel_nummer] ?></span></td>
<td class="row2" width="250" align="left" valign="middle"> <span class="postbody"><?php echo $rows[klant_email] ?></span></td>
</table>

<?php } ?>

</form>
<br><br>

<table border="0" cellpadding="4" cellspacing="1" align="center" width="1380">
<tr>
<td colspan="1" nowrap="nowrap" align="left" valign="center"> <span class="postbody"><input name="activate" type="submit" id="activate" value="Verstuur bevestiging" />  <input name="deactivate" type="submit" id="deactivate" value="Verwijder bestelling" onclick="return confirm('Weet je zeker dat je deze regel(s) wilt verwijderen?')"/></span></td>
</tr>
</table>


<?php

}
else{

header('Location: http://website.com');

}


?>
Link to comment
Share on other sites

Sorry - I don't wade thru other people's giant blocks of code.  Show me the isolated part that does what I suggested previously.

 

PS - I may be alone in my practice, but I design my scripts to put all the html in one function and I place php vars that contain all the dynamic parts of the page.  Makes reading and debugging SOOO much easier and also makes following the php easier since it isn't intermingled with that html code.  Think about it.  Generally I have one <? tag per script. 

Link to comment
Share on other sites

One thing I suggest is:  learn the usage of CSS.  You can save an awful lot of code with css.  Consider your <td> tags with the alignments you are doing for EVERY element of your table (much of which is deprecated BTW).

<head>

<style type='text/css'>

td

{

  padding:4px;

  text-align:left;

  vertical-align:middle;

}

</style>

</head>

 

This will do all your alignments for every table cell.  Should you need to make some cells different, simply create a class and reference it in the <td> tags that you want to be different, as in:

 

(in your css section as above)

.td_bottom

{

  vertical-align:bottom;

}

 

will create a different alignment for those td cells that have 'class="td_bottom"' in them.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.