php pagination with date and not serial number - php

I have database with 80 rows currently and it increases day by day as i am conducting online lectures for doctors on every tuesday and saturday. For Members of my site, recording of these lectures are available.
My database contains columns like lecture_start_date, lecture_end_date, display_time (+45 minutes to lecture end date-time)...
currently 80 lectures recording links are available on single page. so i created pagination for 10 lectures each. code is as follows..
$sql = "SELECT COUNT(lecture_start) FROM es_lecture_master";
$rs_result = mysql_query($sql);
$row = mysql_fetch_row($rs_result);
$total_records = $row[0];
$total_pages = ceil($total_records / 10);
for ($i=1; $i<=$total_pages; $i++) {
echo "<button><a class=\"page\" href='lec_history_p.php?page=".$i."'>".$i." </a></button>";
};
And
$current_date=date("Y-m-d H:i:s");
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * 10;
$sql = "SELECT * FROM es_lecture_master where display_time <'".$current_date."' ORDER BY `lecture_start` DESC limit $start_from, 10";
$rs_result = mysql_query ($sql);
$ss=mysql_num_rows($rs_result);
$counts= sizeof($arrayreversed);
while($data=mysql_fetch_assoc($rs_result)) {
<div align="left">Lecture No :<div class="numberCircle" style="display:inline;"> <? echo $ss;?></div></div>
<table width="80%" style="text-align:left;" align="center" border="0" cellspacing="4" cellpadding="4" class="tabl">
<tr>
<td width="32%">E-Sambhasha Subject : </td>
<td ><?=stripslashes($data["lecture_subject"])?></td>
</tr>
<tr>
<td width="32%">Lecturer :</td>
<td><?=$data["lecturer_name"]?></td>
</tr>
<tr>
<td width="32%">IST Day & Date :</td>
<td><?=date("l ",strtotime($data['lecture_start']))?>,<?=date("d M Y",strtotime($data['lecture_start']));?>
</td>
</tr>
<tr>
<td width="32%" style="background-color:#d44302; color:#f4f4af;">IST Timing :</td>
<td><?=date("h:i:s A ",strtotime($data['lecture_start']))?> - <?=date("h:i:s A ",strtotime($data['lecture_end']))?></td>
</tr>
<tr>
<td width="32%">Session Recording :</td>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabl"><tr>
<td width="26%">
<button data-fancybox-href="<?php echo $data['recording_link'];?>" class="fancy fancybox.iframe more_info_btn" >Play Recording</button> </td>
</tr></table>
</td>
</tr>
</table>
</div>
With This Code I am getting result as following image.
But I don't want to show serial numbers for pagination but want to show date range of lectures conducted for pagination...e.g. button with label ="From 13 March 2014 To 7 Jan 2014" (here 13 march will be lecture start date of Lecture shown on Top on page 1) instead of Button "1", button with label = "From 06 Jan 2014 To 12 October 2014" Instead of Button with label "2"?
(database contains lecture_start_date and lecture_end_date columns)
Also in Lecture No., on every page it shows Lecture No. 10 to 1..instead of that how to show like on page 1 Lecture 80 to 70, on page 2 - lecture no. 70 to 60 and so on.. ?
see image -

Related

Display a row with total amount of shift wise

I provide staff members to a site. They work shit wise Day and Night.
To make monthly Invoice I display the staff according to Shift wise.
Like
Day Shift
Emp Name Days Amount
A 30 1200
B 25 1000
Night Shift
C 27 1100
D 26 1050
I want to display a row with total Amount Shift Wise
I have this code
<?php
$temp='';
foreach ( $rows as $row)
{
///To Display Shift Row///////
if($temp!=$row->shift_type)
{
?>
<tr><td style="font-weight:bold"><?php echo $row->shift_type;?> Shift</td></tr>
<tr style=" border-top:3px solid #CCC">
<th style="text-align:center">Staff Name</th>
<th style="text-align:center"> Days</th>
<th style="text-align:center"> Amount</th>
</tr>
<?php $temp = $row->shift_type;
}
?>
////To Display Staff Members with Salry////
first_name.$row->last_name; ?>
<td align="center"><?php echo $row->week_days; ?></td>
<td align="center">$<?php echo $weekdaysamount= $row->week_days*$row->week_day_rate;
$totalweekdaysamount+=$weekdaysamount;?>
</td>
</tr>
<?php } ?>
This make the total of all rows . I want a row with total of Shift wise.
Should be like this
Day Shift
Emp Name Days Amount
A 30 1200
B 25 1000
Total 2200
Night Shift
C 27 1100
D 26 1050
Total 2150
<html>
<table style="width:100%">
<?php
require("stackoverflow_connect.php");
$extract=mysql_query("SELECT * FROM `employees` WHERE shift_type='Day'");
echo 'Day Shift';
echo '
<tr>
<td>Emp Name</td>
<td>Days</td>
<td>Amount</td>
</tr>
';
$total=0;
while($row=mysql_fetch_assoc($extract))
{
$total=$total+($row['week_day_rate']*$row['week_day']);
echo '
<tr>
<td>'.$row['name'].'</td>
<td>'.$row['week_day'].'</td>
<td>'.$row['week_day_rate']*$row['week_day'].'</td>
</tr>';
}
echo '<tr>
<td></td>
<td>Day Total</td>
<td>'.$total.'</td>
</tr>';
$extract_n=mysql_query("SELECT * FROM `employees` WHERE shift_type='Night'");
$total=0;
while($row_n=mysql_fetch_assoc($extract_n))
{
$total=$total+($row['week_day_rate']*$row['week_day']);
echo '
<tr>
<td>'.$row['name'].'</td>
<td>'.$row['week_day'].'</td>
<td>'.$row['week_day_rate']*$row['week_day'].'</td>
</tr>';
}
echo '<tr>
<td></td>
<td>Night Total</td>
<td>'.$total.'</td>
</tr>';
?>
</table>
<html>
You want to display the total shift wise,first order the result by the shift_type when fetching data.Then while calculating check the shift_type and if it is different from the previous record reset the value to zero.Something like below should work
$previous_shilft='';//Initally outside the foreach
if($previous_shilft!=$row->shift_type && !empty($previous_shilft)){
echo '<tr>
<td>Total</td>
<td></td>
<td>'.$totalweekdaysamount.'</td>
</tr>';//Display the row
}
if($previous_shilft!=$row->shift_type){
$totalweekdaysamount=0;
}
$totalweekdaysamount+=$weekdaysamount;
$previous_shilft=$row->shift_type;//For next loop check change the value

How to send each client ID data from Database to each different email

I m struggling to send Each ClientID Information from Database to their specific Email Address.
My training exercise was to use this SQL (See Below) that have 3 different tables that are as follow: Client, Sites, Job_Cards.
Now I have create a SQL that gives me the output that I need. But my problem is based at the fact that 1 clientID may have one or Many SiteID. one SiteID may have one and many Job_Card#.
When I create my PHP Script the Data Displays as follow: Link on a HTML page.
My Question is in 2 Parts:
How can I format the table to Display ONLY 1 ClientID or ClientName with the list of Job#, site name and Description of this single Client?
How may I send an Email to Each of the ClientName Without Duplicate ID. And What php script will be good to use to send Emails to Each Clients?
Here is my PHP Script and My SQL Statment:
$sqlSelect = "SELECT DISTINCT(cl.client_id),
client_name,
DATE(jb.date),
jb.job_number,
jb.repair,
st.site_name
FROM
job_cards jb
INNER JOIN
clients cl ON (cl.client_id = jb.client_id)
LEFT JOIN
sites st on (st.site_id = jb.site_id)
WHERE
jb.completed = 1
AND cl.client_id = jb.client_id
AND jb.date >= DATE_ADD(DATE(NOW()), INTERVAL - 30 DAY)
ORDER BY cl.client_name ASC";
//echo $sqlSelect;
$tresult = mysql_query($sqlSelect);
//die("ss");
//$dataCount = mysql_num_rows($result);
while($userData = mysql_fetch_assoc($tresult)){
if($i%2==0)
$classname = 'evenRow';
else if($i%2==1)
//extract($userData);
?>
</table>
</td>
</tr>
<tr>
<td align='center' height="30" style="font-size:14px;">
<b><?php echo $userData['client_name'];?></b>
</td>
<td align='center'></td>
<td>
<table width='100%' cellpadding= '1' border='0'>
<thead>
<tr>
<td style="font-size:13px; text-align:Left;"><b>Date</b></td>
<td style="font-size:13px; text-align:Left;"><b>Job #</b></td>
<td style="font-size:13px; text-align:left;"><b>Site name</b></td>
<td style="font-size:13px; text-align:left;"><b>Description</b></td>
</tr>
</thead>
<tr class='<?php if(isset($classname)) echo $classname;?>'>
<tr>
<td>
<?php echo mysql_real_escape_string ($userData['DATE(jb.date)']); ?>
</td>
<td>
<?php echo mysql_real_escape_string($userData['job_number']);?>
</td>
<td>
<?php echo mysql_real_escape_string($userData['site_name']);?>
</td>
<td>
<?php echo mysql_real_escape_string($userData['repair']);?>
</td>
</tr>
<?php $i++;
}
?>
</tr>
</table>
<table width='100%' cellpadding= '1' border='1'>
<tr>
</tr>
</table>
Please May Some 1 Help me. I tried What I could But Still I cannot send emails and the Table format doesn't display the way I want.
Thank.

php and mysql - how can i sum up the total number of payments?

this is my php code:
viewPayments.php
Select release date the loan transaction:
while($row = mysql_fetch_array($select)){
echo "<option>".$row['rel_date']."</option>";
}
?>
</select>
<input class="button_search" type="submit" name="search_btn" value="Submit">
When the submit button is clicked, the selected date is shown together with the payments of that released date:
<?php
if(isset($_POST['search_btn'])){
$date = $_POST['date'];
$query = mysql_query("SELECT m.MID,lt.advanced_interrest,
lt.due_date, lt.rel_date,lt.loan_amount,
p.pay_date,p.OR_no,p.pay_amount,
(lt.loan_amount - p.pay_amount) as balance,
DATE_ADD(lt.rel_date, lt.due_date) AS days
FROM members m ,loan_transaction lt , payment p WHERE m.MID = lt.MID AND lt.MID = p.MID AND m.MID = p.MID AND lt.rel_date = $date");
echo '
<tr>
<td>
<td> <input type="text" class="textbox" value ="Date Selected "> </td>
<td>
<input type="text" class="textbox" value ="'.$date.'">
</td>
</tr>';
?>
<tr id="tr">
<th id="sth">Payment Date</th>
<th id="sth">OR No</th>
<th id="sth">Amount </th>
<th id="sth">Current Balance</th>
<th id="sth">Penalty</th>
</tr>
<?php
while ($data =mysql_fetch_array($query)) {
echo '
<tr>
<td id="row">'.$data['pay_date'].'</td>
<td id="row">'.$data['OR_no'].'</td>
<td id="row">'.$data['pay_amount'].'</td>
<td id="row">'.$data['balance'].'</td>
</tr>';
}
This part is to sum up the total payments.
$q = mysql_query("SELECT SUM(payment.pay_amount) as sum
FROM payment,loan_transaction where loan_transaction.rel_date = $date");
$result = mysql_fetch_array($q);
if($result){
$sum = $result['sum'];
echo '
<tr>
<td id = "row"> Total Paid Amount </td>
<td> </td>
<td id ="row">'.$sum.'</td>
</tr>
';
This SQL code for the sum works in the console but it wont display on my browser. what's wrong with my code?
How can I also update my current balance?

Is it possible to <br> every 10 table rows in CSS?

My script basically loads data from my database and I have to <br> somewhere but it wont work because its a huge table. So I need to format this table so every 10 rows there is a <br>.
<table align="center" cellspacing="0" cellpadding="0">
<?php
$date = mysql_query("SELECT DISTINCT `date` FROM `matches`");
while($daterow = mysql_fetch_assoc($date)){
echo ' <tr>
<td style="width:60px; background-color:#000000;"><font color="#FFFFFF" style="font-size:11px">'.$daterow['date'].'</font></td>
</tr>
';
$query = mysql_query("SELECT hour, team1, team2, goalsteam1, goalsteam2, competition FROM `matches` WHERE `date`='". $daterow['date'] ."'");
while($row = mysql_fetch_array($query)){
$teamtest = mysql_query("SELECT teamname FROM `teams` WHERE `team`='".$row['team1']."'");
$teamtestrow = mysql_fetch_assoc($teamtest);
$hour = substr($row['hour'],0,5);
echo '
<tr class="teamtable">
<td style="width:60px; font-size:11px;">'.$hour.'</td>
<td style="width:145px; font-size:11px;">'.$teamrow['teamtest'].'</td>
<td style="width:15px; font-size:11px;">'.$row['goalsteam1'].'</td>
<td style="width:15px; font-size:11px;">'.$row['goalsteam2'].'</td>
<td style="width:145px; font-size:11px;">'.$row['team2'].'</td>
<td style="width:120; font-size:11px;">'.$row['competition'].'</td>
</tr>';
}
}
?>
</table>
Or just <br> before every date. When I tried it will just leave a huge blank space up but still no space between the date and matches.
Not too sure if CSS can handle this. And unclear on where you expect a break to occur based on the code you are sharing. But in general you would use the modulus operator in PHP would be a good start. Knowing that maybe this would work for you:
<table align="center" cellspacing="0" cellpadding="0">
<?php
$date = mysql_query("SELECT DISTINCT `date` FROM `matches`");
$counter = 0;
while($daterow = mysql_fetch_assoc($date)){
echo ' <tr>
<td style="width:60px; background-color:#000000;"><font color="#FFFFFF" style="font-size:11px">'.$daterow['date'].'</font></td>
</tr>
';
$query = mysql_query("SELECT hour, team1, team2, goalsteam1, goalsteam2, competition FROM `matches` WHERE `date`='". $daterow['date'] ."'");
while($row = mysql_fetch_array($query)){
$teamtest = mysql_query("SELECT teamname FROM `teams` WHERE `team`='".$row['team1']."'");
$teamtestrow = mysql_fetch_assoc($teamtest);
$hour = substr($row['hour'],0,5);
echo '
<tr class="teamtable">
<td style="width:60px; font-size:11px;">'.$hour.'</td>
<td style="width:145px; font-size:11px;">'.$teamrow['teamtest'].'</td>
<td style="width:15px; font-size:11px;">'.$row['goalsteam1'].'</td>
<td style="width:15px; font-size:11px;">'.$row['goalsteam2'].'</td>
<td style="width:145px; font-size:11px;">'.$row['team2'].'</td>
<td style="width:120; font-size:11px;">'.$row['competition'].'</td>
</tr>';
$counter++;
// Do a modulus check.
if ($counter % 10 == 0) {
echo "<tr><td colspan="6"> </td></tr>";
}
}
}
?>
</table>
The key chunk of code is this:
$counter++;
// Do a modulus check.
if ($counter % 10 == 0) {
echo "<tr><td colspan="6"> </td></tr>";
}
On each loop $counter is incremented by 1. And using the modulus operator in the if() statement we check for every 10th item & then do something. In this case insert a row with an in it.

php splitting records in multiple pages is not working properly

i'm facing problem in getting the apprpriate values for some cells ....In the first page i'm getting the appropriate result..but in the next pages the values for product information,total price and profit from order all have value 0 but all the other fields are containing correct information.
Five records are shown per page.. The code is given below:
<?include"dbconnect.php"?>
session_start();
?>
<?include "adminhead.php"?>
<?include "adminleftnav.php"?>
<div id="seasonal">
<table width="635" border="0" align="left" bgcolor="#CCCCCC" >
<tr>
<td>
<table width="635" border="0" align="left" >
<tr>
<td width="52" bgcolor="#E0EBED">Order Number</td>
<td width="150" bgcolor="#E0EBED">Product Information</td>
<td width="100" bgcolor="#E0EBED">Total Price(TK)</td>
<td width="90" bgcolor="#E0EBED">Order Date</td>
<td width="80" bgcolor="#E0EBED">Payment Status</td>
<td width="100" bgcolor="#E0EBED">Profit from order(TK)</td>
</tr>
</table>
</td>
</tr>
<?php
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1)*5 ;
$sql = "Select distinct order_no,date,payment_status from product_order_info order by order_no ASC LIMIT $start_from,5";
$query_for_order1 = mysql_query ($sql);
?>
<tr>
<td>
<table id="foo" border="1" bgcolor="#f4eddb" cellspacing="2" cellborder="2" width=635>
<? while($row_for_my_order1=mysql_fetch_assoc($query_for_order1))
{
?>
<tr>
<td width=52>
<?echo $row_for_my_order1['order_no'];?>
</td>
<td width=156>
<?
$sql1 = "Select * from product_order_info where order_no= '$row_for_my_order1[order_no]' order by order_no ASC LIMIT $start_from,5";
$query_for_order = mysql_query($sql1);
while($row_for_my_order=mysql_fetch_assoc($query_for_order))
{
$query_for_product_details=mysql_query("select * from product where product_no='$row_for_my_order[product_id]' ");
$row_for_product_details=mysql_fetch_array($query_for_product_details);
?>
<br>
<?echo $row_for_product_details['product_name'];
?>
<br>
Quantity
<?echo $row_for_my_order['quantity'];
}
?>
</td>
<td width=106>
<?
$total=0;
$sql1 = "Select * from product_order_info where order_no= '$row_for_my_order1[order_no]' order by order_no ASC LIMIT $start_from,5";
$query_for_order = mysql_query($sql1);
while($row_for_my_order2=mysql_fetch_assoc($query_for_order))
{
$query_for_product_details=mysql_query("select * from product where product_no='$row_for_my_order2[product_id]' ");
$row_for_product_details=mysql_fetch_array($query_for_product_details);
$total = $total+ $row_for_product_details['sell_price'] * $row_for_my_order2['quantity'];
}
echo $total;
?>
</td>
<td width=90>
<?echo $row_for_my_order1['date'];?>
</td>
<td>
<?echo $row_for_my_order1['payment_status'];?>
</td>
<td width=100>
<? $total=0;
$sql1 = "Select * from product_order_info where order_no= '$row_for_my_order1[order_no]' order by order_no ASC LIMIT $start_from,5";
$query_for_order = mysql_query($sql1);
while($row_for_my_order3=mysql_fetch_assoc($query_for_order))
{
$total=$total+$row_for_my_order3['profit'];
}
echo $total; ?>
</td>
</tr>
<?
}
?>
</table>
</div>
<?php
$sql = "SELECT DISTINCT COUNT(order_no) FROM product_order_info";
$rs_result = mysql_query($sql);
$row = mysql_fetch_row($rs_result);
$total_records = $row[0];
$total_pages = ceil($total_records / 5);
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='view_order.php?page=".$i."'>".$i."</a> ";
};
?>
<?include "footer1.php"?>
Please help me in this regard...
You should delete LIMIT $start_from,5 from every query except the first one. As Dagon pointed out, you should consider the possibility to use a single query, to reduce the number of queries to the SQL server.

Categories