Please see the code that I have within the BODY of PHPMailer. System reports a Syntax error on the line $mail->Body .= ''. $row['updated_by'] . '';
I have read through documentation of PHPMailer but have not been able to find much about inserting PHP within the BODY part of the email.
$mail->Body = <<
<table class="table table-striped table-bordered sortable">
<thead>
<tr>
<th>Sales Agent</th>
<th>Company</th>
<th>Contact</th>
<th>Contact Medium</th>
<th>Contact Date</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<?php
include 'database.php';
$pdo = Database::connect();
$yesterday = date('Y-m-d 00:00:00',strtotime("-1 days"));
$sql = "SELECT * FROM `customer_history` WHERE `date_contacted` = '$yesterday'";
$sth = $pdo->prepare($sql);
$sth->execute();
foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row)
{
$mail->Body .= '<tr>';
$mail->Body .= '<td>'. $row['updated_by'] . '</td>';
$mail->Body .= '<td>'. $row['company_name'] . '</td>';
$mail->Body .= '<td>'. $row['first_name'] . '</td>';
$mail->Body .= '<td>'. $row['contacted_by'] . '</td>';
$mail->Body .= '<td>'. $row['date_contacted'] . '</td>';
$mail->Body .= '<td>'. $row['last_result'] . '</td>';
$mail->Body .= '</td>';
$mail->Body .= '</tr>';
}
Database::disconnect();
?>
</tbody>
</table>
</div>
</div>
END;
Firstly execute db query and after that add result to the body.
<?php
$history = '';
include 'database.php';
$pdo = Database::connect();
$yesterday = date('Y-m-d 00:00:00',strtotime("-1 days"));
$sql = "SELECT * FROM `customer_history` WHERE `date_contacted` = '$yesterday'";
$sth = $pdo->prepare($sql);
$sth->execute();
foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row)
{
$history .= '<tr>';
$history .= '<td>'. $row['updated_by'] . '</td>';
$history .= '<td>'. $row['company_name'] . '</td>';
$history .= '<td>'. $row['first_name'] . '</td>';
$history .= '<td>'. $row['contacted_by'] . '</td>';
$history .= '<td>'. $row['date_contacted'] . '</td>';
$history .= '<td>'. $row['last_result'] . '</td>';
$history .= '</td>';
$history .= '</tr>';
}
Database::disconnect();
// Mail body
$mail->Body = <<<EOF
...
<tbody>
{$history}
</tbody>
...
EOF;
Related
My search won't work and I don't know why. I would like to search for clients or tickets in my database. When I click on search while the SEARCH field ( input) is empty I get all clients BUT when I type some thing into the field I get nothing. Here is the code :
<table class="table table-bordered" id="datatable">
<thead>
<tr>
<th width="6%">name</th>
<th width="6%">prenom</th>
<th width="12%">adresse</th>
<th width="3%">codepost</th>
<th width="6%">ville</th>
<th width="5%">telephone</th>
<th width="8%">email</th>
<th width="6%">type</th>
<th width="5%">Action</th>
</tr>
</thead>
<tbody>
<?php
require 'database.php';
$db = Database::connect();
$statement = $db->query("SELECT * FROM clients WHERE 'prenom' LIKE '%" . $_POST['prenom'] . "%' ORDER BY client_id DESC" );
while($item = $statement->fetch())
{
echo '<tr>';
// echo '<td>'. $item['id'] . '</td>';
echo '<td>'. $item['name'] . '</td>';
echo '<td>'. $item['prenom'] . '</td>';
echo '<td>'. $item['adress'] . '</td>';
echo '<td>'. $item['codepost'] . '</td>';
echo '<td>'. $item['ville'] . '</td>';
echo '<td>'. $item['telephone'] . '</td>';
echo '<td>'. $item['email'] . '</td>';
echo '<td>'. $item['type'] . '</td>';
echo '<td width=150>';
echo '<a class="btn btn-default " href="view.php?id='.$item['client_id'].'"><span class="glyphicon glyphicon-eye-open"></span></a>';
echo ' ';
echo '<a class="btn btn-primary" href="update.php?id='.$item['client_id'].'"><span class="glyphicon glyphicon-pencil"></span></a>';
echo ' ';
echo '<a class="btn btn-danger" href="deleteclient.php?id='.$item['client_id'].'"><span class="glyphicon glyphicon-remove"></span> </a>';
echo '</td>';
echo '</tr>';
}
Database::disconnect();
?>
</tbody>
</table>
i finaly did it .. thanks to who helped me (
Sam Onela ) here is the code if some one need ``it := `
name
prenom
adresse
codepost
ville
telephone
email
type
Action
prepare(" SELECT * FROM clients WHERE name LIKE ? ");
$req->execute(array('%' .$searchq. '%')) ;
$count = $req->rowCount();
echo " $count Résulta(s) trouvé pour <strong >$searchq></strong><hr/> " ;
while($data = $req->fetch()) {
echo '<tr>';
echo '<td>'. $data['name'] . '</td>';
echo '<td>'. $data['prenom'] . '</td>';
echo '<td>'. $data['adress'] . '</td>';
echo '<td>'. $data['codepost'] . '</td>';
echo '<td>'. $data['ville'] . '</td>';
echo '<td>'. $data['telephone'] . '</td>';
echo '<td>'. $data['email'] . '</td>';
echo '<td>'. $data['type'] . '</td>';
echo '<td width=150>';
echo '<a class="btn btn-default " href="view.php?id='.$data['client_id'].'"><span class="glyphicon glyphicon-eye-open"></span></a>';
echo ' ';
echo '<a class="btn btn-primary" href="update.php?id='.$data['client_id'].'"><span class="glyphicon glyphicon-pencil"></span></a>';
echo ' ';
echo '<a class="btn btn-danger" href="deleteclient.php?id='.$data['client_id'].'"><span class="glyphicon glyphicon-remove"></span> </a>';
echo '</td>';
echo '</tr>';
}
}
Database::disconnect();
?>
</tbody>
</table>`
I have this foreach loop:
foreach($dataSet1 as $data) {
$result .= '<tr>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . $data['CUST_ID'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . $data['LAST_NAME'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . $data['PHONE'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . $data['ORD_COUNT'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . date('m/d/Y' ,strtotime($data['DATE_LAST'])) . '</td>';
$result .= '</tr>';
}
EDIT
I need to separate the users with bottom border, based on $data['CUST_ID'];
Example:
$data['CUST_ID'] = 2;
$data['CUST_ID'] = 2;
$data['CUST_ID'] = 2;
bottom-border;
$data['CUST_ID'] = 25;
$data['CUST_ID'] = 25;
bottom-border;
$data['CUST_ID'] = 2131;
bottom-border;...
Just save the previous ID in a variable and check it, and update it, in each loop iteration:
$previousId = '';
foreach($dataSet1 as $data):
if ($previousId !== '' && $previousId !== $data['CUST_ID']) {
// put a border
}
$previousId = $data['CUST_ID'];
$result .= '<tr>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . $data['CUST_ID'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . $data['LAST_NAME'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . $data['PHONE'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . $data['ORD_COUNT'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . date('m/d/Y' ,strtotime($data['DATE_LAST'])) . '</td>';
$result .= '</tr>';
endforeach;
You need to set a variable outside the loop that will keep this information:
$previous = null;
So inside your loop you can ask:
if ($data['CUST_ID'] == $previous) {
// current customer id same as previous id
} else {
// not the same
}
And in the very end of your loop set the precious variable to the current one:
$previous = $data['CUST_ID'];
/* You have to declare a variable outside of the foreach loop
which will hold your value for previous id as you proceed through the loop.*/
$prev_cust_id = '';
foreach($dataSet1 as $data):
// Then inside the loop, declare a the border styling as empty.
//Make it not empty and as you need it to be if your IDs do not match.
$add_border = '';
if($data['CUST_ID'] != $prev_cust_id && $prev_cust_id != ''){
$add_border = 'style="border-bottom:1px solid black;"';
}
$result .= '<tr>';
// Assign border styling variable to your HTML element.
$result .= '<td '.$add_border.' bgcolor="#EBEBEB" width="100" class="veranda">' . $data['CUST_ID'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . $data['LAST_NAME'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . $data['PHONE'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . $data['ORD_COUNT'] . '</td>';
$result .= '<td bgcolor="#EBEBEB" width="100" class="veranda">' . date('m/d/Y' ,strtotime($data['DATE_LAST'])) . '</td>';
$result .= '</tr>';
// Set current ID as previous ID before ending the loop for current ID.
$prev_cust_id = $data['CUST_ID'];
endforeach;
my table has many columns so it resulted to over-spanning in its width. i want to make it scrollable horizontally so that it would fit in the screen and it will look more neat and organized. I guess css will do with property overflow hidden. but I dont know where to put my html codes. hope someone can help.
<?php
$serverName = "kwe-PC\SQLEXPRESS";
$connectionInfo = array("Database" => "customerdb", "UID" => "dbadmin", "PWD" => "kwe");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
//declare the SQL statement that will query the database
$query = "SELECT * FROM Customer_Details";
//execute the SQL query and return records
$result = sqlsrv_query($conn, $query)
or die(print_r(sqlsrv_errors(), true));
//Show results in table
$o = '<table border=1 id="myTable">
<thead>
<tr>
<th> </th>
<th>REC NUMBER</th>
<th>CUSTOMER ID</th>
<th>CUSTOMER NAME</th>
<th>SEC-REGISTERED NAME</th>
<th>TIN NUMBER</th>
<th>STORE TYPE</th>
<th>SIZE OF BUSINESS</th>
<th>SELLER ID</th>
<th>DATE OF ESTABLISHMENT</th>
<th>TELEPHONE#/FAX</th>
<th>PAYMENT TERMS</th>
<th>SHIPPING INSTRUCTIONS</th>
<th>NUMBER OF DOORS</th>
<th>NUMBER OF WAREHOUSES</th>
<th>OWNER</th>
<th>PURCHASER/S</th>
<th>ACCOUNTING HEAD</th>
<th>WAREHOUSE HEAD</th>
<th>OTHER PERSONNEL</th>
<th>PAYMENT TERMS 2</th>
<th>COLLECTION SCHEDULE</th>
<th>DISCOUNT</th>
<th>VOLUME</th>
<th>MERCHANDISING</th>
<th>VEHICLE</th>
<th>DISTRIBUTION</th>
<th>CSL</th>
<th>ASSORTMENT</th>
<th>PRICING</th>
<th>MARGIN</th>
<th>PRICE</th>
<th>PROMOTION</th>
<th>PEOPLE</th>
<th>OTHERS</th>
<th>REPLENISHMENT ORDERS</th>
<th>ASSORTMENT/MERCHANDISING</th>
<th>NEW PRODUCTS</th>
<th>PRICING/PROMOTION</th>
<th>PICTURE</th>
</tr>
</thead><tbody>';
while ($record = sqlsrv_fetch_array($result)) {
$o .= '<tr><td><input type=radio name=id value=' . $record ['Rec_No'] . '></td>';
$o .= '<td>' . $record ['Rec_No'] . '</td>';
$o .= '<td>' . $record ['Cust_ID'] . '</td>';
$o .='<td>' . $record ['Cust_Name'] . '</td>';
$o .='<td>' . $record ['SEC_Name'] . '</td>';
$o .='<td>' . $record ['TIN Number'] . '</td>';
$o .='<td>' . $record ['Store_Type'] . '</td>';
$o .='<td>' . $record ['Size of Business'] . '</td>';
$o .='<td>' . $record ['Seller_ID'] . '</td>';
$o .='<td>' . date('F d, Y', strtotime($record ['Date of Establishment'])) . '</td>';
$o .='<td>' . $record ['Telephone/Fax'] . '</td>';
$o .='<td>' . $record ['Payment Terms'] . '</td>';
$o .='<td>' . $record ['Shipping Instructions'] . '</td>';
$o .='<td>' . $record ['Number of Doors'] . '</td>';
$o .='<td>' . $record ['Number of Warehouses'] . '</td>';
$o .='<td>' . $record ['Owner'] . '</td>';
$o .='<td>' . $record ['Purchaser(s)'] . '</td>';
$o .='<td>' . $record ['Accounting Head'] . '</td>';
$o .='<td>' . $record ['Warehouse Head'] . '</td>';
$o .='<td>' . $record ['Other Personnel'] . '</td>';
$o .='<td>' . $record ['Payment Terms 2'] . '</td>';
$o .='<td>' . $record ['Collection Schedule'] . '</td>';
$o .='<td>' . $record ['Discount'] . '</td>';
$o .='<td>' . $record ['Volume'] . '</td>';
$o .='<td>' . $record ['Merchandising'] . '</td>';
$o .='<td>' . $record ['Marketing Vehicle'] . '</td>';
$o .='<td>' . $record ['Distribution'] . '</td>';
$o .='<td>' . $record ['CSL'] . '</td>';
$o .='<td>' . $record ['Assortment'] . '</td>';
$o .='<td>' . $record ['Pricing'] . '</td>';
$o .='<td>' . $record ['Margin'] . '</td>';
$o .='<td>' . $record ['Price'] . '</td>';
$o .='<td>' . $record ['Promotion'] . '</td>';
$o .='<td>' . $record ['People'] . '</td>';
$o .='<td>' . $record ['Others'] . '</td>';
$o .='<td>' . $record ['Replenishment Orders'] . '</td>';
$o .='<td>' . $record ['Assortment/Merchandising'] . '</td>';
$o .='<td>' . $record ['New Products'] . '</td>';
$o .='<td>' . $record ['Pricing/Promotions'] . '</td>';
$o .='<td><img height=127 width=127 src="data:image/png;base64,' . $record['image'] . '"></td>';
$o .='</tr>';
}
$o .= '</tbody></table>';
?>
<form action="delete.php" method="POST">
<?php echo $o; ?>
<br><input type="submit" value="Delete" name="submit">
</form>
<?php
if (isset($_POST['submit'])) {
$serverName = "kwe-PC\SQLEXPRESS";
$connectionInfo = array("Database" => "customerdb", "UID" => "dbadmin", "PWD" => "kwe");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
if(isset($_POST['id']) && !empty($_POST['id'])){
$sql = "DELETE FROM Customer_Details WHERE Rec_No =" . $_POST['id'];
sqlsrv_query($conn, $sql);
$ids = $_POST['id'];
echo "Row with Record Number: " . $ids . " has been deleted!";
}else{
echo "ID is empty";
}
}
?>
In css
#myTable{overflow-x: scroll}
http://www.w3schools.com/cssref/css3_pr_overflow-x.asp
1) Wrap table with a div which has a class
<div class="wrap">
<table>
...
</table>
</div>
2) Give wrap class overflow-x property with scroll
overflow-x: scroll
3) Make it fixed width
width: 300px;
4) Also take care of vertically visibility
overflow-y: visible;
.wrap {
overflow-x: scroll;
overflow-y: visible;
width: 300px;
}
Here is a simple working example.
I am having syntax error with my following code
<?php
If (!empty($_SESSION['LogedinStudentId'])) {
echo '<h3>Your Scholarship Applications:</h3>
<table width="100%" class="table table-bordered">
<tr>
<th scope="col">Sr.No.</th>
<th scope="col">Date of Application</th>
<th scope="col">Course Type</th>
<th scope="col">Course Description</th>
<th scope="col">Subject</th>
<th scope="col">Applied for Semester No.</th>
<th scope="col">Scholarship Status</th>
<th scope="col">View / Print</th>
</tr>
<tr>
<td>' . ++$serialno . '</td>
<td>' . if(empty($row_studentdashboard['DateofApplication'])) {
echo ' ';
} else {
echo date("d-m-Y", strtotime($row_studentdashboard['DateofApplication']));
};
. '</td>
<td>' . $row_studentdashboard['CourseType'] .'</td>
<td>' . $row_studentdashboard['CourseDescriptionLong'] .'</td>
<td>' . $row_studentdashboard['Subject'] .'</td>
<td>' . $row_studentdashboard['ApplyForSemYear'] .'</td>
<td>' . $row_studentdashboard['ScholarshipStatus'] .'</td>
<td>View / Print</td>
</tr>
</table>';
} else {
echo '<h3>You do not have any application pending</h4>';
}
?>
I am getting syntax error on line no. 17 and 22. The second (nested) if statement is throwing syntax error. I can not judge what is wrong. If I run this second if statement outside of the html it is working fine.
Can anyone point out what's wrong?
What you are doing is an if-statement inside of echo-statement. It is wrong.
Run second if-statement outside of html and create a variable that you later print in your html.
A kind of this:
if(empty($row_studentdashboard['DateofApplication'])) {
$text = ' ';
} else {
$text = date("d-m-Y", strtotime($row_studentdashboard['DateofApplication']));
}
.....
<td>' . ++$serialno . '</td>
<td>' . $text . '</td>
You 're not supposed to concatenate an if statement to a string. That is what you did on line 17/18
Try :
<?php
if (isset($_SESSION['LogedinStudentId']) && !empty($_SESSION['LogedinStudentId'])) {
$out = '<h3>Your Scholarship Applications:</h3>';
$out .= '<table width="100%" class="table table-bordered">';
$out .= '<tr>';
$out .= '<th scope="col">Sr.No.</th>';
$out .= '<th scope="col">Date of Application</th>';
$out .= '<th scope="col">Course Type</th>';
$out .= '<th scope="col">Course Description</th>';
$out .= '<th scope="col">Subject</th>';
$out .= '<th scope="col">Applied for Semester No.</th>';
$out .= '<th scope="col">Scholarship Status</th>';
$out .= '<th scope="col">View / Print</th>';
$out .= '</tr>';
$out .= '<tr>';
$out .= '<td>' . ++$serialno . '</td>';
$out .= '<td>';
if(!isset($row_studentdashboard['DateofApplication']) || empty($row_studentdashboard['DateofApplication'])) {
$out .= ' ';
} else {
$out .= date("d-m-Y", strtotime($row_studentdashboard['DateofApplication']));
};
$out .= '</td>';
$out .= '<td>' . $row_studentdashboard['CourseType'] .'</td>';
$out .= '<td>' . $row_studentdashboard['CourseDescriptionLong'] .'</td>';
$out .= '<td>' . $row_studentdashboard['Subject'] .'</td>';
$out .= '<td>' . $row_studentdashboard['ApplyForSemYear'] .'</td>';
$out .= '<td>' . $row_studentdashboard['ScholarshipStatus'] .'</td>';
$out .= '<td>View / Print</td>';
$out .= '</tr>';
$out .= '</table>';
} else {
$out = '<h3>You do not have any application pending</h4>';
}
echo $out;
I am fetching data from Mysql database and populating them in a table.
However, i cannot seem to make the cell autofit to contents. I have tried width as the property of the table but i cant get it to work
Would really appreciate your help. Thanks
Here's what i have done so far
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<table class="table table-bordered" style="width:100%">
<thead>
<tr>
<th><center>ID</center></th>
<th>Name</th>
<th><center>Email</center></th>
<th>Number</th>
<th>Package</th>
<th>Flexibility</th>
<th >Date</th>
<th>Departuring From</th>
<th>Departure Date</th>
<th>Destination</th>
<th>Arrival Date</th>
<th>Price</th>
<th>Consolidator</th>
</tr>
</thead>
<tbody>
<?php
$query = 'SELECT * FROM queries';
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['name'] . '</td>';
echo '<td>'. $row['email'] . '</td>';
echo '<td>'. $row['contactnumber'] . '</td>';
echo '<td>'. $row['packagedetails'] . '</td>';
echo '<td>'. $row['flexibility'] . '</td>';
echo '<td>'. $row['datetoday'] . '</td>';
echo '<td>'. $row['departure'] . '</td>';
echo '<td>'. $row['dateofdeparture'] . '</td>';
echo '<td>'. $row['destination'] . '</td>';
echo '<td>'. $row['dateofarrival'] . '</td>';
echo '<td>'. $row['price'] . '</td>';
echo '<td>'. $row['vendor'] . '</td>';
echo '<td width=250>';
echo '<a class="btn btn-success" href="readquery.php?id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn btn-success" href="updatequery.php?id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="deletequery.php?id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
I never see you echo </tr> or </td>. It would be helpful to give us an output of the HTML being generated by your while loop.
The problem was not with my table. To make it work, i increased the width of my container in which my table was inside, and it worked