I have been stuck on this problem for a while. My requirements are to email data from mySQL to a client. I took code from another page in my company's codebase that works when it is emailed.
The problem that I am encountering is that it is emailing only one character per row.
Here is my code:
$message = "
<br /><hr /><br /><table style='font-size: 12px; width:100%'>
<tr>
<td td width='25%'><strong>Oligo Name</strong></td>
<td width='10%'><strong>Base</strong></td>
<td width='10%'><strong>Scale</strong></td>
<td width='10%'><strong>Mod</strong></td>
<td width='10%'><strong>Mod Position</strong></td>
<td style='word-break: break-all; width: 500px;'><strong>Oligo Sequence</strong></td>
<td width='15%' style='text-align: right'><strong>Price</strong></td>
</tr>";
$SampleID = 0;
$maxrow = $OligoQty;
for ($i; $i < $maxrow; $i++) {
if(trim($SampleName) == '' && trim($Sequence) == '')
continue;
// $SampleID++;
$bases = preg_replace('/\s+/', '', $Sequence);
$seq_length = strlen($bases);
$message .= "
<tr>
<td width='200'>{$SampleIDS} . {$SampleName[$i]}</td>
<td width='40'>{$sequence_length[$i]}</td>
<td width='40'>{$SampleScale[$i]}</td>
<td width='40'>{$modification[$i]}</td>
<td width='40'>{$mod_position[$i]}</td>
<td style='word-break: break-all; width: 500px;'>{$Sequence[$i]}</td>
</tr>";
</tr>";
}
When I remove the for loop, it prints out the row perfectly:
I believe there is something wrong with my for loop that is causing it to do that and I am not sure why. I hard coded $maxrow to 2 and that is why I am getting 2 rows for the email. Any help would be appreciated!
Related
Need some help.
I am trying to create a script that sends an html email to a shopper with a list of all the orderd items. I want the items fetched from the database to be stored in a single variable so that I can embed it in the message variable of mail() function. Or Just the Items fetched to be embeded in the email.
Have tried the code below but it only displays 1 item and not all that are in the loop. How can I do it?
I'll be grateful for your help.
$message3 = "
</td>
</tr>
<tr bgcolor='#A8CE58'><td><b>ITEMS ORDERED</b></td></tr>
<tr>
<td>
<table border='' style='margin-bottom: 10px; margin-top:10px; padding: 1px;border-right: : 1px solid #000;'>
<tr align='left'>
<th>---</th>
<th>Name</th>
<th>Qty</th>
<th>Total</th>
</tr>";
$ress= mysqli_query($server, "SELECT * FROM ordered_products WHERE session='$session'");
mysqli_data_seek($ress, 0);
while($colms=mysqli_fetch_array($ress, MYSQLI_NUM))
{
$message4 =
"
<tr align='left'>
<td><img src='e_images/$colms[8]' height='auto' width='50px'></td>
<td>$colms[2]</td>
<td >$colms[9]</td>
<td>ksh.$colms[5]</td>
</tr>";
}
$message = "$message3". $message4;
You need to concatenate the string
$message4 = '';
while($colms=mysqli_fetch_array($ress, MYSQLI_NUM)) {
$message4 .= //your html
}
What you doing now is overwrite the value of $message4 each time in the loop
With
.=
You solve this. Don't forget to declare the variable before the loop, else you will get a warning from PHP.
I am a back end dev for a WordPress website: https://westtechshipping.com.
The admin side is where the majority of our time is spent. We deal with packages ordered by our customers and deliver them. I have a system put in place where you upload a .csv file and the PHP function reads the contents of the .csv, then updates the data into the database, then sends out an email to our clients.
Over time we realized that we cannot do a .csv upload with more than 30 entries because we would get errors like this one
I took this image from google images because I cannot recreate the error at the moment due to the time of this post, but the error is similar.
We also sometimes get a page that says this
We've tried many things and are not sure what the issue is. These hiccups cause our data to be uploaded twice and multiple emails to be sent out to each client.
We have spoken to our server hosting, go daddy, and followed their recommendations of editing our user.ini accordingly.
This are our PHP settings from our user.ini
If this is an issue with the code, below is the current code for our .csv upload feature.
if(isset($_POST["submitcsv"])) // Upload Package Amount CSV File
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;
$c2 = 0;
$row = 1;
while(($filesop = fgetcsv($handle, 1000, ",")) !== false)// What?
{
$Name = $filesop[0];
$AccID = $filesop[1];
$Freight = $filesop[2];
$Handling = $filesop[3];
$Consolidation = $filesop[4];
$Duty = $filesop[5];
$VTax = $filesop[6];
$Delivery = $filesop[7];
$Insurance = $filesop[8];
$Amount = $filesop[9];
$Statuscsv = $filesop[10];
$Pickup = $filesop[11];
$trackingnumber =$filesop[12];
if($row == 1) { $row++; continue;}
$num = count($filesop);
//Separating First name
$First_Name = substr($Name,0,strrpos($Name,' '));
if(strrpos($Name, ' ')!== false){
$First_Name = $First_Name;
}else{
$First_Name = $Name;
}
//Getting rid of blank costs
if(empty($Freight)){$Freight = "0";}
if(empty($Handling) ){$Handling = "0";}
if(empty($Consolidation)){$Consolidation = "0";}
if(empty($Duty) ){$Duty = "0";}
if(empty($VTax) ){$VTax = "0";}
if(empty($Delivery)){$Delivery = "0";}
if(empty($Insurance)){$Insurance = "0";}
if(empty($Amount)){$Amount = "0";}
//$pkg = get_packages_query($trackingnumber);
//$pkginv = get_invoices_by_trackingid($trackingnumber);
$userID = explode('WT100',$AccID);
$userdata = get_userdata( $userID[1] );
$site_name = get_bloginfo('name');
$messageinv = " <style>
#media screen (max-width:768px) { /* smartphones, iPhone, portrait 480x320 phones */
#packagetable{
margin-left:20px;
}
}
</style>
<div style='font-size:15px;'>
<strong> Dear ".$First_Name."</strong>, <br><br>
".$site_name." has a package available for you. You can come in to collect during our working hours of Monday- Friday 8AM to 5PM and Saturdays 9AM to 1PM.
</div>
<br><br>
<table id='packagetable' style='border:1px solid #8EAADB; margin-left:150px;'>
<tr class ='invhead' style='background-color:#4472C4; color:white;'>
<th>Charges</th>
<th>Amount (EC)</th>
</tr>
<tr class ='2ndtr' >
<td > Tracking Number </td>
<td> ".$trackingnumber."</td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Shipping Charge: </td>
<td> $".$Freight." </td>
</tr>
<tr class ='2ndtr' >
<td > Duty Charge: </td>
<td> $".$Duty."</td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Handling Fee: </td>
<td> $".$Handling." </td>
</tr>
<tr class ='2ndtr' >
<td > Consolidation Fee: </td>
<td> $".$Consolidation." </td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Delivery Fee: </td>
<td> $".$Delivery." </td>
</tr>
<tr class ='2ndtr' >
<td > <strong>Total Amount: </strong> </td>
<td><strong>$".$Amount."</strong> </td>
</tr>
</table>
<div>
<br><br>
Thanks for using our service! We appreciate it.
<br><br>
Regards,<br>
".$site_name."
<br>______________________________________________________<br><br>
<strong>Call Us</strong><br><br>
<strong>Rodney Bay</strong>: 458-9378 <strong>Castries</strong>: 451-9378 <strong>Vieux Fort</strong>: 454-9378
</div>
";
$messageinvadmin .=
" <style>
#media screen (max-width:768px) { /* smartphones, iPhone, portrait 480x320 phones */
#packagetable{
margin-left:20px;
}
}
</style>
<div><strong>".$Name."</strong> with email address ".$userdata->data->user_email.", had an invoice update. <br><br>
View the changes below
</div>
<br><br>
<table id='packagetable' style='border:1px solid #8EAADB; margin-left:150px;'>
<tr class ='invhead' style='background-color:#4472C4; color:white;'>
<th>Charges</th>
<th>Amount (EC)</th>
</tr>
<tr class ='2ndtr' >
<td > Tracking Number </td>
<td> ".$trackingnumber."</td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Shipping Charge: </td>
<td> $".$Freight." </td>
</tr>
<tr class ='2ndtr' >
<td > Duty Charge: </td>
<td> $".$Duty."</td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Handling Fee: </td>
<td> $".$Handling." </td>
</tr>
<tr class ='2ndtr' >
<td > Consolidation Fee: </td>
<td> $".$Consolidation." </td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Delivery Fee: </td>
<td> $".$Delivery." </td>
</tr>
<tr class ='2ndtr' >
<td > <strong>Total Amount: </strong> </td>
<td><strong>$".$Amount."</strong> </td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Delivery Fee: </td>
<td> $".$Delivery." </td>
</tr>
</table>
_______________________________________________________
<br><br>
";
$closing = "Regards,<br>
".$site_name."
<br>______________________________________________________<br><br>
<strong>Call Us</strong><br><br>
<strong>Rodney Bay</strong>: 458-9378 <strong>Castries</strong>: 451-9378 <strong>Vieux Fort</strong>: 454-9378
</div>
";
$invtotalsql = mysql_fetch_assoc(mysql_query("SELECT invoice_total_charges FROM wp_xq4w067xaq_customer_invoice WHERE invoice_tracking_number = '$trackingnumber'"));
$packstatsql = mysql_fetch_assoc(mysql_query("SELECT pms_status FROM wp_xq4w067xaq_package WHERE tracking_id = '$trackingnumber'"));
if($Statuscsv == "Collected & Paid"){
$Statuscsv = 5;
}if($Statuscsv == "Available for Pick-Up"){
$Statuscsv = 4;
}if($Statuscsv == "Pending Invoice"){
$Statuscsv = 3;
}if($Statuscsv == "Paid"){
$Statuscsv = 7;
}if($Statuscsv == "Collected"){
$Statuscsv = 9;
}if($Statuscsv == "Shipped"){
$Statuscsv = 2;
}if($Statuscsv == "Received"){
$Statuscsv = 1;
}
if($invtotalsql['invoice_total_charges'] !== $Amount OR $packstatsql['pms_status'] !== $Statuscsv){
send_email_pkg2($userdata->data->user_email, $messageinv, $site_name. ' Package Amount Update',$userdata->user_email_2,$userdata->user_email_3);
//send_email_pkg("shipping#westtg.com", $messageinvadmin, $site_name. "Package Amount update");
//send_email_pkg("5sp4lr9#gmail.com", $messageinvadmin, $site_name. "Invoices");
//send_email_pkg("5sp4lr9#gmail.com", $message3, $site_name. "Minimum Invoices");
}
$sql = "UPDATE wp_xq4w067xaq_package SET pms_full_name='$Name',pms_status='$Statuscsv',pms_amount_owned='$Amount',pms_pickup='$Pickup' WHERE tracking_id='$trackingnumber'";
mysql_query($sql);
$c = $c + 1; // count number of package info updated
$sql2 = "UPDATE wp_xq4w067xaq_customer_invoice SET invoice_shipping_charge='$Freight',invoice_handling_fee='$Handling',invoice_consolidation_fee='$Consolidation',invoice_duty_charge='$Duty',invoice_added_tax='$Vtax',invoice_delivery_fee='$Delivery',invoice_insurance='$Insurance',invoice_total_charges='$Amount' WHERE invoice_tracking_number='$trackingnumber'";
mysql_query($sql2);
$c2 = $c2 + 1; // count number of invoices updated
//update_invoice2();
}
$finaladmin = $messageinvadmin.$closing;
send_email_pkg("shipping#westtg.com", $finaladmin, $site_name. "Package Amount update");
// Success OR Error Message
if($sql AND $sql2){
echo "Your database has imported successfully. You have inserted ". $c ." records in packages and ".$c2." records in invoices";
}else{
echo "Sorry! There is some problem.";
}
}
for ($i=0; $i<=$lines; $i++)
{
//get each line and exlplode it..
$part = explode('|', $file[$i]);
//now start printing ..
echo'<tr>
<td width="20%">'.$part[0].'</td>
<td width="20%">'.$part[1].'</td>
<td width="20%">'.$part[2].'</td>
<td width="20%">'.$part[3].'</td>
<td width="20%">'.$part[4].'</td>
</tr>';
}
This is my code, it read's from a text file and explode in table, but I have a little problem here cause this one needs to be link.
<td width="20%">'.$part[2].'</td>
.$part[2]. is just a word from file but it has query like www.somesite.com/?q= There at the end I need to have that
word from file
that kind of code did not work for me
<td width="20%"> <a herf='www.somesite.com/?q=''.$part[2].'> '.$part[2].' </a> </td>
I realy need some help with this...
<?php
//first, get the file...
$file = file('req.txt');
//now count the lines ..
$lines = count($file);
//start the table here..
echo'<table border="2" width="100%">';
echo'<tr>
<td width="20%">Naslov</td>
<td width="20%">Vrsta</td>
<td width="20%">IP</td>
<td width="20%">Dodano (DD.MM.YY - HH.MM)</td>
<td width="20%">Status</td>
</tr>';
//start the loop to get all lines in the table..
for ($i=0; $i<=$lines; $i++) {
//get each line and exlplode it..
$part = explode('|', $file[$i]);
//now start printing ..
echo'<tr>
<td width="20%">'.$part[0].'</td>
<td width="20%">'.$part[1].'</td>
<td width="20%">'.$part[2].'</td>
<td width="20%">'.$part[3].'</td>
<td width="20%">'.$part[4].'</td>
</tr>';
}
//close the table so HTML wont suffer :P
echo'</table>';
?>
This should produce this but ip column need to be link...
I think vprintf() is your friend.
<?php
$fmt = '<tr>
<td>%1$s</td>
<td>%2$s</td>
<td>%3$s</td>
<td>%4$s</td>
<td>%5%s</td>
</tr>';
for ($i=0; $i<=$lines; $i++)
{
// get each line and explode it..
$part = explode('|', $file[$i]);
// now start printing ..
vprintf($fmt, $part);
}
And put the width="20%" into your CSS.
I solve it alone with changing some values in input script "file writer"
$savestring = $title . "|" . $genre . "|<a href=http://www.example.com/ip?ip=" . $ip . ">" . $ip . "|" . $date . "|Za Naložit \n";
it works now ty anyway :)
I'm filling an HTML table with data from the following query:
$content_downloads = mysql_query( "SELECT
s.site, s.machine, d.projectid, d.directorySize, d.connectivityError,
d.blocked, d.blockedBy, d.blockedSince, d.errorString, d.dashboardTimeStamp
FROM rtcdb.site_machines s
LEFT JOIN rtcdb.downloadstatuses d
on (s.site = d.site and s.machine = d.machine)
where s.site in (select d2.site from rtcdb.downloadstatuses d2
where d2.dashboardTimeStamp > (SELECT DATE_ADD(max(dashboardTimeStamp),INTERVAL -1 DAY)
from rtcdb.downloadstatuses)) order by s.site, s.machine asc", $con) or die(mysql_error());
This query is going into an HTML table based on the following HTML/PHP:
<table>
<thead>
<tr>
<th>Site</th>
<th>Machine</th>
<th>Project ID</th>
<th>Folder Size</th>
<th>Error Description</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysql_fetch_assoc($content_downloads)) {
$error_string = "";
if ($row["connectivityError"] == true ) {
$error_string = "COULD NOT CONNECT: " . $row["errorString"];
}
elseif ($row["blocked"] == true ) {
$error_string = "BLOCKED BY LOCK OWNED BY: " . $row["blockedBy"] . " " . $row["blockedSince"];
}
echo '
<tr>
<td>'.$row["site"].'</td>
<td>'.$row["machine"].'</td>
<td>'.$row["projectid"].'</td>
<td>'.$row["directorySize"].'</td>
<td style = "text-align: left; color: red;">'.$error_string.'</td>
</tr> ';
}
?>
</tbody>
</table>
The error description column in this table rarely has contents. As you can see, when it does, a PHP conditional function (the if and ifelse functions) places a statement before the error description to make the description more understandable. One thing you may notice is that I am coloring the text of error descriptions red. The thing that I am struggling with that I need your help on is to selectively style an entire row with a background-color of yellow, when the error description cell in that row has a value. In other words, when the two conditionals I wrote are true, I would like to make the background-color of the row that includes that error description yellow.
It seems pretty simple, but I have tried various options and can't seem to figure it out. Any tips Stack Overflow?
Check if the error string is empty:
echo '
<tr' . (empty($error_string) ? '' : ' style="background-color:yellow;"') . '>
<td>'.$row["site"].'</td>
<td>'.$row["machine"].'</td>
<td>'.$row["projectid"].'</td>
<td>'.$row["directorySize"].'</td>
<td style = "text-align: left; color: red;">'.$error_string.'</td>
</tr> ';
What I would try is setting a class on the row of interest:
<tr class="highLight">
and then use CSS to set the background color of the cells in that row:
tr.highLight td {background-color: yellow; }
Set the class attribute is your error string has content.
Try this:
if($error_string != "")
{
echo '<tr class="error-row"';
}else{
echo '<tr>';
}
echo '<td>'.$row["site"].'</td>
<td>'.$row["machine"].'</td>
<td>'.$row["projectid"].'</td>
<td>'.$row["directorySize"].'</td>
<td style = "text-align: left; color: red;">'.$error_string.'</td>
</tr> ';
and add this to your stylesheet:
.error-row{background:yellow;}
if you want less code you can use the if shorthand too like this:
echo '<tr' . ($error_string == "" ? '' : 'class="error-row"') . '>
<td>'.$row["site"].'</td>
<td>'.$row["machine"].'</td>
<td>'.$row["projectid"].'</td>
<td>'.$row["directorySize"].'</td>
<td style = "text-align: left; color: red;">'.$error_string.'</td>
</tr> ';
Ok, I figured out what to do, and I apologize for not using jQuery or class attributes. I appreciate everyones help, and am being honest when I say that everyone's comments and answers helped me figure it out. Here's the solution:
if ($error_string != ""){
echo '
<tr style = "background-color: yellow;">
<td>'.$row["site"].'</td>
<td>'.$row["machine"].'</td>
<td>'.$row["projectid"].'</td>
<td>'.$row["directorySize"].'</td>
<td style = "text-align: left; color: red;">'.$error_string.'</td>
</tr> ';
}
else {
echo '
<tr>
<td>'.$row["site"].'</td>
<td>'.$row["machine"].'</td>
<td>'.$row["projectid"].'</td>
<td>'.$row["directorySize"].'</td>
<td style = "text-align: left; color: red;">'.$error_string.'</td>
</tr> ';
}
Thanks for everyone's help!
This question already exists:
Closed 10 years ago.
Possible Duplicate:
w3 validation issue
i can't pass the w3c validator for my site ( http://www.bbway.com )
i got 4 error's
1- Line 294, Column 19: end tag for "tr" which is not finished
</td></tr><tr></tr></table>
2- Line 362, Column 19: end tag for "tr" which is not finished
</td></tr><tr></tr></table>
3- Line 400, Column 19: end tag for "tr" which is not finished
</td></tr><tr></tr></table>
4- Line 438, Column 19: end tag for "tr" which is not finished
</td></tr><tr></tr></table>
all the top errors comes from my (multi columns code) i use this code
$getnewbrds=$db->query("select id,userid,title,added_date,active
from brd
where active='1' order by id desc limit 9");
echo '<table width="100%" border="0" cellpadding="5"><tr>';
$count = 0;
$max = 3;
while($fetch_newbrds=$db->fetch($getnewbrds)){
$count++;
$getbrduser = get_val("id,name","users","where id='$fetch_newbrds[userid]'","name");
$getbrduseri = get_val("id,name","users","where id='$fetch_newbrds[userid]'","id");
echo '<td align="center" width="30%" valign="top">
<table border="0" width="100%" cellspacing="3" cellpadding="3">
<tr>
<td height="50" colspan="2" align="center">
<a href="showbrd-'.$fetch_newbrds['id'].'.html" title="'.$fetch_newbrds['title'].'">
'.$fetch_newbrds['title'].'</a>
</td>
</tr>
<tr>
<td colspan="2" align="right" class="brduseronmain">
<a href="users-'.$getbrduseri.'.html" title="'.$getbrduser.'">'.$getbrduser.'
<span>'.$fetch_newbrds['added_date'].'</span>
</a>
</td>
</tr>
</table>
</td>';
if($count >= $max){
$count = 0;
echo '</tr><tr>';
}
}
echo '</tr></table>';
could you please share your fixes for this issue.
Your issue is here:
if($count >= $max){
$count = 0;
echo '</tr><tr>';
}
You need to add logic so that on the last iteration it doesn't output an empty row.
You could do this with another counter or better yet don't pre-wrap the <tr> outside the while.
Here is your code, fixed, I think, didn't test it since you didn't provide data I could test with it, find more info below.
$getnewbrds=$db->query("
select
id,
userid,
title,
added_date,
active
from
brd
where
active='1'
order by
id desc
limit 9
");
$count = 0;
$max = 3;
$html = '<table width="100%" border="0" cellpadding="5">';
while($fetch_newbrds = $db->fetch($getnewbrds)) {
$count++;
if($count % $max === 1){
$html .= '<tr>';
}
$getbrduser = get_val("id,name","users","where id='$fetch_newbrds[userid]'","name");
$getbrduseri = get_val("id,name","users","where id='$fetch_newbrds[userid]'","id");
$html .= '
<td align="center" width="30%" valign="top">
<table border="0" width="100%" cellspacing="3" cellpadding="3">
<tr>
<td height="50" colspan="2" align="center">
<a href="showbrd-'.$fetch_newbrds['id'].'.html" title="'.$fetch_newbrds['title'].'">
'.$fetch_newbrds['title'].'
</a>
</td>
</tr>
<tr>
<td colspan="2" align="right" class="brduseronmain">
<a href="users-'.$getbrduseri.'.html" title="'.$getbrduser.'">'.$getbrduser.'
<span>'.$fetch_newbrds['added_date'].'</span>
</a>
</td>
</tr>
</table>
</td>
';
if($count % $max === 0){
$html .= '</tr>';
}
}
if($count % $max !== 0) {
while($count % $max !== 0) {
$html .= '<td></td>';
$count++;
}
$html .= '</tr>';
}
$html .= '</table>';
echo $html;
Few things I did
Indented your code properly; do that yourself before even trying to
post a question
Captured the html in a variable first echo'ed when
done; right to the output is not the best way...
I used modulus to figure out if $count divided by $max leaves 1 to determine if I should open a new <tr>... and did the same check to see if the remainder would be 0 to see if I need to close it... Then at last after the while I check if the
was closed or not, if not add <td></td> until it is to keep the html valid and eventually close the last <tr>.