0

Hello, I have following page which shows 10 records per page (pagination) what I want is, it gives me a total of "Total (Price+Shipping)" at the end of the page. How can I do that? I am trying hard but with no access

<?php include('connect.php'); ?>

<?php
 
 //This checks to see if there is a page number. If not, it will set it to page 1 
 if (isset($_GET['pagenum']))  {   $pagenum=$_GET['pagenum'];  }else  {  $pagenum=1;  }if (isset($_GET['pagenum']))
  { 
  $pagenum=$_GET['pagenum'];
  }
else
  {
  $pagenum=1;
  }

 
 //Here we count the number of results 
 //Edit $data to be your query 
 $data = mysql_query("SELECT * FROM `info` 
ORDER BY id DESC") or die(mysql_error()); 
 $rows = mysql_num_rows($data); 
 
 //This is the number of results displayed per page 
 $page_rows = 10; 
 
 //This tells us the page number of our last page 
 $last = ceil($rows/$page_rows); 
 
 //this makes sure the page number isn't below one, or more than our maximum pages 
 if ($pagenum < 1) 
 { 
 $pagenum = 1; 
 } 
 elseif ($pagenum > $last) 
 { 
 $pagenum = $last; 
 } 
 
 //This sets the range to display in our query 
 $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 
//This is your query again, the same one... the only difference is we add $max into it
 $data_p = mysql_query("SELECT * FROM info ORDER BY id DESC $max ") or die(mysql_error()); ?><style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
}
-->
</style>

<title>Shipment record</title><table width="100%">
  <tr>
    <td><a href="../index.php" >Go to Home</a></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="0">

<tr> 
<td><table width="100%" border="1" cellspacing="1" cellpadding="0">
  <tr>
    <td width="2%" height="61" align="center"><p><strong>Id</strong></p></td>
    <td width="4%" align="center"><p><strong>eBay ID</strong></p></td>
    <td width="12%" align="center"><strong>Item</strong></td>
    <td width="17%" align="center"><p ><strong>To/Address</strong></p></td>
    <td width="16%" align="center"><strong>Order Date</strong></td>
    <td width="11%" align="center"><p><strong>Date Sent</strong></p></td>
    <td width="18%" align="center"><strong>Total</strong> (Price+Shipping)</td>
    <td width="20%" align="center"><p><strong>Tracking</strong> (Click on the code to check status)</p></td>
  </tr>
  <?php
while($rows=mysql_fetch_array($data_p)){
?>
  <tr>
    <td align="center"><?php $id[]=$rows['id']; ?>
      <?php echo $rows['id']; ?></td>
    <td align="CENTER"><strong><?php echo $rows['user']; ?></strong></td>
    <td align="center"><div style="color:#039"><?php echo $rows['item']; ?></div></td>
    <td align="justify"><?php echo nl2br ( $rows['addr']); ?></td>
    <td align="justify"><?php echo $rows['date']; ?></td>
    <td align="justify"><?php echo $rows['datesent']; ?></td>
    <td align="center"><strong><?php echo $rows['total']; ?></strong></td>
    <td align="center"><?php
if($rows['tracking'] != '')
{
echo '<a href="http://ipsweb.ptcmysore.gov.in/ipswebtracking/IPSWeb_item_events.asp?itemid='.$rows['tracking'].' " target="_blank">' . $rows['tracking'] . '</a>';
}
?></td>
  </tr>
  <?php
}
?>
  <tr><td></td>
    <td colspan="7" align="center"></td>
  </tr>
</table></td>
</tr>
</form>
</table><?php 
 // This shows the user what page they are on, and the total number of pages
 echo " --Page $pagenum of $last-- <p>";
 
 // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
 if ($pagenum == 1) 
 {
 } 
 else 
 {
 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
 echo " ";
 $previous = $pagenum-1;
 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
 } 

 //just a spacer
 echo " ---- ";

 //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
 if ($pagenum == $last) 
 {
 } 
 else {
 $next = $pagenum+1;
 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
 echo " ";
 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
 } 
 ?>
<table width="100%">
  <tr>
    <td><a href="../index.php" >Go to Home</a></td>
  </tr>
</table>
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by tomato.pgn
0

You can do this by just using a simple sql query....
You can do it by using "LIMIT" it will limit the number of records.
If you have problem in that please notify that....
Code will be somewhat like this:-

SELECT sum(price) from info limit 10,10

In this the first parameter passed is for the value from where you have to start adding values and next is for the number of records whose sum is to be calculated....
Hope this is clear...
PS-If your problem is solved mark the thread as solved

Edited by tomato.pgn: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.