I need to send emails with the content of a PHP page, but I am having trouble, as far as I could do is creating static format in HTML but if tomorrow the data has more rows the email will be incomplete,
I will share part of my mail.php
//The query
$wipAgingQuery = $dbconnection->query("
SELECT
CAST(datein AS DATE) AS [Date_In],
COUNT(lab) AS [Count_of_Jobs],
ROUND(SUM(COUNT(lab)) OVER (ORDER BY datein DESC) * 100.0 / SUM(COUNT(lab)) OVER (),2) AS [Cumulative]
FROM [DailyWIP].[dbo].[WIP_Daily_Load]
WHERE location = 'USA' AND dateload BETWEEN CONCAT(CAST(GETDATE() AS DATE),' 11:30:00.000') AND CONCAT(CAST(GETDATE() AS DATE),' 14:00:00.000')
GROUP BY datein ORDER BY datein DESC;");
$jobInWip = $wipAgingQuery->fetchAll(PDO::FETCH_OBJ);
//Assign Query Result in Variable
foreach ($jobInWip as $jobInWip) {
$wipDateIn = $jobInWip -> Date_In;
$wipCount = $jobInWip -> Count_of_Jobs;
$wipCumulative = $jobInWip -> Lab_Cumulative;
$totalJobCount = $totalJobCount + $wipCount;
}
//HTML inside the Mailer Body
<div class='row'>
<div class='col-12'>
<h1>Current Day WIP: Aging</h1>
<table class='table table-bordered'>
<thead class='thead-dark'>
<tr>
<th>Date In</th>
<th>Count of Jobs</th>
<th>Lab Cumulative</th>
</tr>
</thead>
<tbody>
<tr>
<td>$wipDateIn</td>
<td><p class='text-right'>$wipCount</p></td>
<td><p class='text-right'>$wipCumulative</td>
</tr>
<tr>
<td>Grand Total:</td>
<td><p class='text-right'>$totalJobCount</p></td>
</tr>
</tbody>
</table>
</div>
</div>
This is the original wipdata.php page where I can manage that problem since the table is being created by a foreach depending on the results of the query, but I don't know how to do something similar in the mail.php
<div class="row">
<div class="col-12">
<h1>Current Day WIP: Aging</h1>
<br>
<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<th>Date In</th>
<th>Count of Jobs</th>
<th>Lab Cumulative</th>
</tr>
</thead>
<tbody>
<?php foreach ($jobInWip as $jobInWip) { ?>
<tr>
<td><?php echo $jobInWip->Date_In ?></td>
<td><?php echo '<p class="text-right">'. number_format($jobInWip->Count_of_Jobs) .'</p>' ?></td>
<td><?php echo '<p class="text-right">'. number_format($jobInWip->Lab_Cumulative, 2) . ' %' ?></td>
</tr>
<?php $totalJobCount = $totalJobCount + $jobInWip->Count_of_Jobs;
} ?>
<tr>
<td><?php echo 'Grand Total: ' ?></td>
<td><?php echo '<p class="text-right">'. number_format($totalJobCount).'</p>'; ?></td>
</tr>
</tbody>
</table>
</div>
</div>
Oh I just found a way around this, I am not sure if this is the best way to solve it but it worked.
foreach ($jobInWip as $jobInWip) {
$wipDateIn = $jobInWip -> Date_In;
$wipCount = $jobInWip -> Count_of_Jobs;
$wipCumulative = $jobInWip -> Lab_Cumulative;
$totalJobCount = $totalJobCount + $wipCount;
$phpmailer-> Body .="<tr>
<td>$wipDateIn</td>
<td><p class='text-right'>$wipCount</p></td>
<td><p class='text-right'>$wipCumulative</td>
</tr>";}
Related
I have a little script on which I am working where I can generate income and expense reports in a nice table, however, I am currently facing some issues with the sort order. Here is my current code:
<div class="panel-body">
<div class="col-md-12">
<?php
$fdate=$_POST['fromdate'];
$tdate=$_POST['todate'];
$rtype=$_POST['requesttype'];
?>
<?php
$source1 = $_POST['fromdate'];
$date1 = new DateTime($source1);
$source2 = $_POST['todate'];
$date2 = new DateTime($source2);
?>
<h5 align="center" style="color:#30a5ff">Expense Report from <?php echo $date1->format('d/m/Y')?> to <?php echo $date2->format('d/m/Y')?></h5>
<hr />
<!-- table start--->
<table class="table table-bordered mg-b-0">
<thead>
<tr>
<th>Date</th>
<th>Description</th>
<th>Category</th>
<th style="text-align:right;">Cash In</th>
<th style="text-align:right;">Cash Out</th>
<th style="text-align:right;background: yellow;">Balance THB</th>
</tr>
</thead>
<?php
$total_e = 0;
$userid=$_SESSION['detsuid'];
$ret=mysqli_query($con,"select * from tblexpense where (ExpenseDate BETWEEN '$fdate' and '$tdate') && (ExpenseType='Expense') && UserId='$userid' ORDER BY ExpenseDate ASC");
$cnt=1;
while ($row=mysqli_fetch_array($ret)) {
$total_e = $total_e+$row['ExpenseCost']
?>
<tbody>
<tr>
<td><?php echo date('d/m/Y', strtotime($row["ExpenseDate"]));?></td>
<td><?php echo $row['ExpenseItem'];?></td>
<td><?php echo $row['ExpenseCat'];?></td>
<td></td>
<td style="text-align:right;"><?php echo number_format($row['ExpenseCost'], 2);?> THB</td>
<td style="text-align:right;"><?php echo number_format($row['ExpenseCost'], 2);?> THB</td>
</tr>
<?php
$cnt=$cnt+1;
}?>
<?php
$total_i =0;
$userid=$_SESSION['detsuid'];
$ret=mysqli_query($con,"select * from tblexpense where (ExpenseDate BETWEEN '$fdate' and '$tdate') && (ExpenseType='Income') && UserId='$userid' ORDER BY ExpenseDate ASC");
$cnt=1;
while ($row=mysqli_fetch_array($ret)) {
$total_i = $total_i+$row['ExpenseCost'];
?>
<tbody>
<tr>
<td><?php echo date('d/m/Y', strtotime($row["ExpenseDate"]));?></td>
<td><?php echo $row['ExpenseItem'];?></td>
<td></td>
<td style="text-align:right;"><?php echo number_format($row['ExpenseCost'], 2);?> THB</td>
<td></td>
<td style="text-align:right;"><?php echo number_format($row['ExpenseCost'], 2);?> THB</td>
</tr>
<?php
$cnt=$cnt+1;
}?>
<tr>
<th colspan="2" style="text-align:left">Grand Total</th>
<th></th>
<th style="text-align:right;"><?php echo number_format($total_i, 2);?> THB</th>
<th style="text-align:right;"><?php echo number_format($total_e, 2);?> THB</th>
<td style="text-align:right; font-weight:bold; background: yellow;"> <?php $ret=mysqli_query($con,"SELECT ExpenseType, SUM(ExpenseCost) FROM tblexpense where (ExpenseDate BETWEEN '$fdate' and '$tdate') && (ExpenseType='Expense') && UserId='$userid' ORDER BY ExpenseDate GROUP BY ExpenseType");
$e_sum = 0;
while ($row=mysqli_fetch_array($ret)) {
//$e_sum = number_format($row['SUM(ExpenseCost)'], 2);
$e_sum = $row['SUM(ExpenseCost)'];
}
?>
<?php $ret=mysqli_query($con,"SELECT ExpenseType, SUM(ExpenseCost) FROM tblexpense where (ExpenseDate BETWEEN '$fdate' and '$tdate') && (ExpenseType='Income') && UserId='$userid'ORDER BY ExpenseDate GROUP BY ExpenseType");
$i_sum = 0;
while ($row=mysqli_fetch_array($ret)) {
//$i_sum = number_format($row['SUM(ExpenseCost)'], 2);
$i_sum = $row['SUM(ExpenseCost)'];
}
echo number_format($i_sum-$e_sum,2);
?> THB</td>
</th>
</tr>
</tbody>
</table>
<!-- table end--->
</div>
</div>
Here a screenshot of the output:
Essentially the output and the values are correct, however, the 2 items I've marked in red (which are Cash out) are not sorted by date as my other values for expenses but add to the top. My ideal goal is to have them all sorted seamlessly by ExpenseDate. What's the best way to have this achieved? Some expert help would be greatly appreciated.
You should merge your two queries into one, and then generate the table output based on the value of ExpenseType e.g.
$ret=mysqli_query($con,"select *
from tblexpense
where (ExpenseDate BETWEEN '$fdate' and '$tdate')
and (ExpenseType='Expense' or ExpenseType='Income')
and UserId='$userid'
ORDER BY ExpenseDate ASC");
then in your loop:
<tr>
<td><?php echo date('d/m/Y', strtotime($row["ExpenseDate"]));?></td>
<td><?php echo $row['ExpenseItem'];?></td>
<td><?php echo $row['ExpenseType'] = 'Expense' ? $row['ExpenseCat'] : '';?></td>
<td style="text-align:right;"><?php echo $row['ExpenseType'] = 'Expense' ? '' : number_format($row['ExpenseCost'], 2); ?> THB</td>
<td style="text-align:right;"><?php echo $row['ExpenseType'] = 'Expense' ? number_format($row['ExpenseCost'], 2) : '';?> THB</td>
<td style="text-align:right;"><?php echo number_format($row['ExpenseCost'], 2);?> THB</td>
</tr>
i'm trying to build a website where users can find location of my company, but i need to hide the information at the first time and only show the location that users needed.
Here's my code:
<?php
$condition = '';
if(isset($_REQUEST['Kota']) and $_REQUEST['Kota']!=""){
$condition .= ' AND Kota LIKE "%'.$_REQUEST['Kota'].'%" ';
}
if(isset($_REQUEST['Outlet']) and $_REQUEST['Outlet']!=""){
$condition .= ' AND Outlet LIKE "%'.$_REQUEST['Outlet'].'%" ';
}
if(isset($_REQUEST['Alamat']) and $_REQUEST['Alamat']!=""){
$condition .= ' AND Alamat LIKE "%'.$_REQUEST['Alamat'].'%" ';
}
$userData = $db->getAllRecords('lokasi','*',$condition,'ORDER BY id DESC');
?>
<div>
<table class="table table-striped table-bordered">
<thead>
<tr class="bg-primary text-white">
<th>No</th>
<th>Cabang GO</th>
<th>Nama Kota</th>
<th>Alamat Outlet</th>
<th>No Telepon</th>
</tr>
</thead>
<tbody>
<?php
$s = '';
foreach($userData as $val){
$s++;
?>
<tr>
<td><?php echo $s;?></td>
<td><?php echo $val['Kota'];?></td>
<td><?php echo $val['Outlet'];?></td>
<td><?php echo $val['Alamat'];?></td>
<td><?php echo $val['Nomor'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
Start out with <div style=visibility:hidden>. Later change it to 'visible' using JavaScript code.
All the Code you have added is fine, you need few more things to add and it will be all working.
Add HTML Form with an input field for entering searching location and a submit button.
<form action="" method="post">
Search Location: <input type="text" name="location"> <input type="submit" name="submit">`enter code here`
</form>
Add "if" Condition to check the user submitted the form and the result from the db is not empty before the table, where you are displaying all the locations.
<?php if(isset($_POST['submit']) && count($userData) > 0){ ?>
<table class="table table-striped table-bordered">
<thead>
<tr class="bg-primary text-white">
<th>No</th>
<th>Cabang GO</th>
<th>Nama Kota</th>
<th>Alamat Outlet</th>
<th>No Telepon</th>
</tr>
</thead>
<tbody>
<?php
$s = '';
foreach($userData as $val){
$s++;
?>
<tr>
<td><?php echo $s;?></td>
<td><?php echo $val['Kota'];?></td>
<td><?php echo $val['Outlet'];?></td>
<td><?php echo $val['Alamat'];?></td>
<td><?php echo $val['Nomor'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
Trying to fetch all results in PHP from MySQL database, but it is leaving the first query.
My MySQL table is in the below image: .
My Code:
<?php
$irn = "33857";
$stmt = $user_home->runQuery('SELECT * FROM invoice WHERE Inv = :inv ORDER BY Sr ASC ');
$stmt->bindParam(':inv',$irn);
$stmt->execute();
$rowc = $stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0)
{
?>
<table id="chiru_inv" class="table table-striped table-hover table-bordered table-responsive">
<tr>
<td colspan="4" align="center">
<h1>Company</br><span style="font-size: 75%;">Number</span></h1>
</td>
</tr>
<tr>
<td colspan="2">
<h3><span style="float: left;"><?php echo $rowc['Customer']; ?> (<?php echo $rowc['Inv']; ?>)</span></h3>
</td>
<td colspan="2">
<h3><span style="float: right;"><?php echo $rowc['Date']; ?></span></h3>
</td>
</tr>
<tr>
<th>Sr.</th>
<th>Item</th>
<th>Qty</th>
<th>Amount</th>
</tr>
<?php
$i = 0;
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
$i++;
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $Item; ?></td>
<td>5</td>
<td>200</td>
</tr>
<?php
}
?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2"><strong><?php echo getIndianCurrency(225); ?>Only</strong></td>
<td><strong>Total:</strong></td>
<td><strong>225</strong></td>
</tr>
</table>
<?php
}
?>
The result when I execute the above code is in the below image:
There are three queries with invoice number 33857, but only two are displayed (leaving the first one)!
I need all to be displayed as per invoice number.
Please help me from sorting out the error/code I made or I left.
The problem in your code is with the line:
$rowc = $stmt->fetch(PDO::FETCH_ASSOC);
in the beginning of your code you're fetching the first row.
You have to update your while loop, like this
<?php
$i = 0;
while($rowc)
{
extract($rowc);
$i++;
?>
<!-- Your HTML/PHP code for the table -->
<?php
$rowc=$stmt->fetch(PDO::FETCH_ASSOC);
}
?>
So, the idea is to fetch the row at the end of the while loop, in order to not lose your first row.
I have a problem i want to put the $message inside the table that is a equivalent as a "Search not found".
Here is my picture outside the table $message = Search not found
View:
<div class="z table-responsive" >
<table class=" table table-hover" >
<thead >
<tr >
<th>ID Number</th>
<th>First name</th>
<th>Middle name</th>
<th>Last name</th>
<th>Sex</th>
</tr>
</thead>
<?php if ( isset($message) ){
echo $message;
} else{ foreach($results as $row){
?>
<tbody>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
Option
</td>
</tr>
</tbody>
<?php }} ?>
</tbody>
</table>
</div>
You are using wrong end tags.
This will print Search not found inside the table with colspan 5 and center aligned
Note: Most of time we check where foreach value is empty ($results). But in your case you are checking some thing else ($message).
Changes
<tr> <!-- Changed -->
<td colspan="5" align="center"><?php echo $message; ?> </td>
</tr>
if ( isset($message) ){ is changed to if (!empty($message)){
Final code
<div class="z table-responsive" >
<table class=" table table-hover" >
<thead >
<tr >
<th>ID Number</th>
<th>First name</th>
<th>Middle name</th>
<th>Last name</th>
<th>Sex</th>
</tr>
</thead>
<tbody>
<?php
if (!empty($message)) # improved
{
?>
<tr> # Changed
<td colspan="5" align="center"><?php echo $message; ?> </td>
</tr>
<?php
}
else
{
foreach($results as $row)
{
?>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
<a href="<?php echo site_url('viewstudentinalpha/viewspecific/'.$row->Id) ?>" class="btn btn-info " style="font-size: 18px;" type="submit" name="submit" role="button">
Option
</a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
Edit 01
In Controller
function search_keyword()
{
$session_data = $this->session->userdata('logged_in');
$data['Username'] = $session_data['Username'];
$keyword = $this->input->post('keyword');
$data['results'] = $this->model_adminlogin->search($keyword);
$this->load->view('result_view',$data);
}
In View
Alter your if like this.
Copy all codes i have added in above for your view. and only change this few lines.
<?php
if (!empty($results)) # Change
{
?>
<tr> # Change
<td colspan="5" align="center"> Search not found </td> # Change
</tr>
<?php
}
else
{
This isn't an issue with CodeIgniter so much as your code. What you are trying to do with the code is to put the message between the <thead> and <tbody>, and not in any table tags.
This is the same as trying to put it between rows in a table, and therefore gets interpreted as not being part of the table, and drawn outside of the table as a result.
If you put the message into the <tbody>, it will go in the right place, so you can do:
<?php if ( isset($message) ){
echo "<tbody><tr><td colspan='5'>" . $message . "</td></tr></tbody>";
}....
try this
<tbody>
<?php
if ( isset($result )
// or if (!isset($message)) //depend on your code
{
foreach($results as $row){
?>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
Option
</td>
</tr>
<?php }}
else
//or elseif(isset($message)) //depend on your code
{
echo $message; ?>
}
</tbody>
</table>
</div>
I have the following php/html code :
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th>Medicine Name</th>
<th>Batch Number</th>
<th>Total Quantity</th>
<th>Expiry Date(s)</th>
<th>Selling Price</th>
<th> Total Price</th>
<th>Issue</th>
</tr>
</thead>
<tbody>
<?php foreach ($prescription as $prescribed): ?>
<tr class="odd gradeX">
<td><?php echo $prescribed['commodity_name']; ?></td>
<td ><?php echo $prescribed['batch_no']; ?></td>
<td><?php echo $prescribed['total_quantity']; ?></td>
<td><?php echo $prescribed['expiry_date']; ?></td>
<td ><?php echo $prescribed['selling_price']; ?></td>
<td><?php
$total_quantity = $prescribed['total_quantity'];
$selling_price = $prescribed['selling_price'];
$total_quantity_float = floatval($total_quantity);
$selling_price_float = floatval($selling_price);
$total_price = $total_quantity_float*$selling_price_float;
echo $total_price;
?></td>
<td>
<a class="issue" href="#types" id="issue">Issue</a>
<input type="hidden" name="batch_no" id="batch_no" value="<?php echo $prescribed['batch_no']; ?>"/>
</td>
<!-- <td> <a id="issue1" class="issue1" href="#types">Issue</a> </td>-->
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
I would like to get the total sum of the total_price variable which is displayed(total_price variable) as a row on the table. This should show the total price for all the commodities, how can I do this best?
try this
<?php
$total_price_sum = 0;
foreach ($prescription as $prescribed){
..
..
$total_price_sum = $total_price_sum + $total_price;
}
echo $total_price_sum;
?>
You can do this by adding to a variable each time you loop. This can be done as follows:
<?php
$grand_total = 0;
foreach ($prescription as $prescribed){
?>
..... all the HTML bits .....
<?
$grand_total = $grand_total + $total_price;
}
echo $grand_total;
?>
Hope that helps.
Regards,
Ralfe