473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Help on pagination please

64
I have a pagination function I am using in a file called functions.php as below
Expand|Select|Wrap|Line Numbers
  1. <? //Pagination functions  function getPagingQuery($sql, $itemPerPage = 10) {    if (isset($_GET['page']) && (int)$_GET['page'] > 0)    {       $page = (int)$_GET['page'];    }    else    {       $page = 1;    }        // start fetching from this row number    $offset = ($page - 1) * $itemPerPage;        return $sql . " LIMIT $offset, $itemPerPage"; }  /*    Get the links to navigate between one result page to another.     */ function getPagingLink($sql, $itemPerPage = 10, $strGet = '') {    $result        = dbQuery($sql);    $pagingLink    = '';    $totalResults  = dbNumRows($result);    $totalPages    = ceil($totalResults / $itemPerPage);        // how many link pages to show    $numLinks      = 10;            // create the paging links only if theres more than one page of results    if ($totalPages > 1) {           $self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ;               if (isset($_GET['page']) && (int)$_GET['page'] > 0) {          $pageNumber = (int)$_GET['page'];       } else {          $pageNumber = 1;       }              // print 'previous' link only if its not       // on page one       if ($pageNumber > 1) {          $page = $pageNumber - 1;          if ($page > 1) {             $prev = " <a href=\"$self?page=$page&$strGet/\">[Prev]</a> ";          } else {             $prev = " <a href=\"$self?$strGet\">[Prev]</a> ";          }                          $first = " <a href=\"$self?$strGet\">[First]</a> ";       } else {          $prev  = ''; // on page one, don't show 'previous' link          $first = ''; // nor 'first page' link       }           // print 'next' link only if its not       // on the last page       if ($pageNumber < $totalPages) {          $page = $pageNumber + 1;          $next = " <a href=\"$self?page=$page&$strGet\">[Next]</a> ";          $last = " <a href=\"$self?page=$totalPages&$strGet\">[Last]</a> ";       } else {          $next = ''; // if on the last page, don't show 'next' link          $last = ''; // nor 'last page' link       }        $start = $pageNumber - ($pageNumber % $numLinks) + 1;       $end   = $start + $numLinks - 1;                    $end   = min($totalPages, $end);              $pagingLink = array();       for($page = $start; $page <= $end; $page++)   {          if ($page == $pageNumber) {             $pagingLink[] = " $page ";   // no need to create a link to current page          } else {             if ($page == 1) {                $pagingLink[] = " <a href=\"$self?$strGet\">$page</a> ";             } else {                   $pagingLink[] = " <a href=\"$self?page=$page&$strGet\">$page</a> ";             }             }           }              $pagingLink = implode(' | ', $pagingLink);              // return the page navigation link       $pagingLink = $first . $prev . $pagingLink . $next . $last;    }        return $pagingLink; } ?>
I include that functions.php in every page because it contains all the functions I need

However, when I add the pagination to my DB functions containing SQLs, it doesn't work. Code below:

Expand|Select|Wrap|Line Numbers
  1. <? function allsales_Today() {    $rowsPerPage = 5;     //$sql = 'SELECT * FROM cstocksales WHERE SaleDate = current_date';    $sql = 'SELECT * FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= SaleDate';        //$result = dbQuery($sql);    $result     = dbQuery(getPagingQuery($sql, $rowsPerPage));    $pagingLink = getPagingLink($sql, $rowsPerPage);        if (dbNumRows($result) == 0) //if none       {         echo '<p><font color=#CC0000><h4>No sales for today were found in the records...</h4></font></p>';       echo 'Go back <a href="index.php">Here</a> for another search.';    }    else    {       echo "<h5>Today's sales sales:<p></h5>";       echo '<table width="100%"  border="1" bordercolor="#000000">';      echo'<tr>';       echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';       echo'<th scope="col" bgcolor="#66FFFF">Category</th>';       echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';       echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';       echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';       echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';       echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';     echo'</tr>';      while($row = dbFetchArray($result))     // while($row = mysql_fetch_array($result))      {                 echo'<tr>';          echo'<td align="center">';          $SaleID = $row["SaleID"];                   echo $SaleID. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Category = $row["Category"];                   echo $Category. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Brand = $row["Brand"];                   echo $Brand. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Quantity = $row["Quantity"];                   echo $Quantity. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $PaidBy = $row["PaidBy"];                   echo $PaidBy. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Cost = $row["Cost"];                   echo $Cost. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $SaleDate = $row["SaleDate"];                   echo $SaleDate. "<br>";                   echo'</td align="center">';                   echo '</tr>';              }    echo'</table>';        //paginating link    echo $pagingLink;        echo "<br>"; echo "<strong>Sales figures:</strong>"; echo "<hr>";        $sql_total = 'SELECT PaidBy, SUM(Cost) FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= SaleDate GROUP BY PaidBy';        $result = dbQuery($sql_total);             while($row = dbFetchArray($result))         {        echo "Total sales by ". $row['PaidBy']. "<font color=#CC0000> =  Kshs <strong>". $row['SUM(Cost)']; echo "</font></strong>";       echo "&nbsp;&nbsp;"; echo"|"; echo "&nbsp;&nbsp;";       }           $sql_total_final = 'SELECT SUM(Cost) FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= SaleDate';        $result = dbQuery($sql_total_final);    while($row = dbFetchArray($result))         {       echo "<strong>All sales = <font color=#CC0000> Kshs " .$row['SUM(Cost)']; echo "</font></strong>" ;       }    }     echo "<br>";    echo '<h4><a href="index.php">Back</a> to sales panel.'; } ?>
The first page is displayed well. When I click next, the page is blank and the URL is
http://localhost/cstock/admin/viewsa...es.php?page=2&

The URL for the search should be

http://localhost/cstock/admin/viewsa...=allsalestoday

Followed by the pagination as a user clicks next or a value in the pagination link

viewsales.php is the file containing sales functions

It only works if I put each function in its own page. My sales functions are many (33 functions) and so they are all in one file called view sales.php in a case statement.

How do I make it work if I have a file that contains all my sales functions and I want to use the pagination in each function?

my pagination function is in a file I call at the top of every page (functions.php)
Expand|Select|Wrap|Line Numbers
  1. <? //Pagination functions  function getPagingQuery($sql, $itemPerPage = 10) {    if (isset($_GET['page']) && (int)$_GET['page'] > 0)    {       $page = (int)$_GET['page'];    }    else    {       $page = 1;    }        // start fetching from this row number    $offset = ($page - 1) * $itemPerPage;        return $sql . " LIMIT $offset, $itemPerPage"; }  /*    Get the links to navigate between one result page to another.     */   function getPagingLink($sql, $itemPerPage = 10, $strGet = '') {    $result        = dbQuery($sql);    $pagingLink    = '';    $totalResults  = dbNumRows($result);    $totalPages    = ceil($totalResults / $itemPerPage);        // how many link pages to show    $numLinks      = 10;            // create the paging links only if theres more than one page of results    if ($totalPages > 1) {           $self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ;               if (isset($_GET['page']) && (int)$_GET['page'] > 0) {          $pageNumber = (int)$_GET['page'];       } else {          $pageNumber = 1;       }              // print 'previous' link only if its not       // on page one       if ($pageNumber > 1) {          $page = $pageNumber - 1;          if ($page > 1) {             $prev = " <a href=\"$self?page=$page&$strGet/\">[Prev]</a> ";             ||             $prev = " <a href=\"$self?action=$action&$strGet/\">[Prev]</a> ";          } else {             $prev = " <a href=\"$self?$strGet\">[Prev]</a> ";          }                          $first = " <a href=\"$self?$strGet\">[First]</a> ";       } else {          $prev  = ''; // on page one, don't show 'previous' link          $first = ''; // nor 'first page' link       }           // print 'next' link only if its not       // on the last page       if ($pageNumber < $totalPages) {          $page = $pageNumber + 1;          $next = " <a href=\"$self?page=$page&$strGet\">[Next]</a> "; || " <a href=\"$self?action=$action&$strGet/\">[Prev]</a> ";          $last = " <a href=\"$self?page=$totalPages&$strGet\">[Last]</a> "; || " <a href=\"$self?action=$action&$strGet/\">[Prev]</a> ";       } else {          $next = ''; // if on the last page, don't show 'next' link          $last = ''; // nor 'last page' link       }        $start = $pageNumber - ($pageNumber % $numLinks) + 1;       $end   = $start + $numLinks - 1;                    $end   = min($totalPages, $end);              $pagingLink = array();       for($page = $start; $page <= $end; $page++)   {          if ($page == $pageNumber) {             $pagingLink[] = " $page ";   // no need to create a link to current page          } else {             if ($page == 1) {                $pagingLink[] = " <a href=\"$self?$strGet\">$page</a> ";             } else {                   $pagingLink[] = " <a href=\"$self?page=$page&$strGet\">$page</a> ";             }             }           }              $pagingLink = implode(' | ', $pagingLink);              // return the page navigation link       $pagingLink = $first . $prev . $pagingLink . $next . $last;    }        return $pagingLink; } ?>
Like in this page (list.php)

Expand|Select|Wrap|Line Numbers
  1. <?php if (!defined('WEB_ROOT')) {    exit; } $rowsPerPage = 5;  $_SESSION['login_return_url'] = $_SERVER['REQUEST_URI']; checkUser();  $sql = "SELECT * FROM fragrancestock"; $result     = dbQuery(getPagingQuery($sql, $rowsPerPage)); $pagingLink = getPagingLink($sql, $rowsPerPage);  $errorMessage = (isset($_GET['cstock_error']) && $_GET['cstock_error'] != '') ? $_GET['cstock_error'] : '&nbsp;'; ?> <form action="index.php?view=add" method="post"  name="frmList" id="frmList">   <table width="100%" border="0" align="center">     <tr class="title_text">       <td width="100">Category</td>       <td width="400">Brand</td>       <td width="100" align="center">Stock</td>       <td width="100">Date Added</td>       <td width="50">Details</td>       <td width="50">Add</td>       <td width="50">Delete</td>     </tr>     <?php if (dbNumRows($result) > 0) {    $i = 0;        while($row = dbFetchAssoc($result)) {       extract($row);                 if ($i%2) {          $class = 'row1';       } else {          $class = 'row2';       }              $i += 1; ?>     <tr class="<?php echo $class; ?>">       <td width="100"><?php echo $Category; ?></td>       <td width="400"><?php echo $Brand; ?></td>       <td width="100" class="inner_border"><?php echo $Quantity; ?></td>       <td width="100"><?php echo $DateAddedStock; ?></td>       <td width="50"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?view=detail&StockID=<?php echo $StockID; ?>">View</a></td>       <td width="50"><a href="javascript:modifyStock(<?php echo $StockID; ?>);"><strong>Add         </strong> </a></td>       <td width="50"><a href="javascript:deleteStock(<?php echo $StockID; ?>);">Delete</a></td>     </tr>     <?php    } // end while   ?>     <tr>       <td colspan="7" align="center">         <?php     echo $pagingLink;    ?>       </td>     </tr>     <?php    } else { ?>     <tr>       <td colspan="7" align="center">No Stock Items Yet</td>     </tr>     <?php } ?>     <tr>       <td colspan="7">&nbsp;</td>     </tr>     <tr>       <td colspan="7" align="right"> <input name="btnAddStock" type="submit" value="New Entry" class="button_image">     </tr>   </table> </form>  <label class="title_text">View Stock:</label> <hr> <table width="100%" border="0">   <tr>     <td><form action="index.php?view=showbybrand" method="post" name="frmByBrand">         <table width="100%" border="0">           <tr>             <td width="200">By Brand:</td>             <td width="200"><select name="sltBrand">                 <option value="0">Select Brand</option>                 <?          $sql = "SELECT DISTINCT Brand FROM cstockitems ORDER BY Brand ASC";          $result = dbQuery($sql);                          if(dbNumRows($result))          {             while($row = dbFetchAssoc($result))             {             echo "<option>$row[Brand]</option>";             }          }                 else                {             echo "<option>No Brands Present</option>";                }      ?>               </select></td>             <td width="200"><input type="submit" name="Submit" value="Show" class="button_image" onClick="return CheckShowBrandByBrand();">             </td>           </tr>         </table>       </form></td>   </tr>   <tr>     <td><form name="frmByCategory" method="post" action="showbycategory.php">         <table width="100%" border="0">           <tr>             <td width="200">By Category:</td>             <td width="200"><select name="sltCategory">                 <option value="0">Select Category</option>                 <?          $sql = "SELECT DISTINCT Category FROM cstockitems ORDER BY Category ASC";          $result = dbQuery($sql);                          if(dbNumRows($result))          {             while($row = dbFetchAssoc($result))             {             echo "<option>$row[Category]</option>";             }          }                 else                {             echo "<option>No Categories Present</option>";                }      ?>               </select></td>             <td width="200"><input type="submit" name="Submit2" value="Show" class="button_image" onClick="return CheckShowBrandByCategory();"></td>           </tr>         </table>       </form></td>   </tr>   <tr>     <td><form name="frmSearchBrand" method="post" action="showbysearch.php">         <table width="100%" border="0">           <tr>             <td width="200">Search:</td>             <td width="200"><input type="text" name="txtSearchBrand" size="40"></td>             <td width="200"><input type="submit" name="Submit3" value="Search" class="button_image" onClick="return CheckShowBrandBySearch();"></td>           </tr>         </table>       </form></td>   </tr> </table> <label class="title_text">Print product list for re-stocking:</label> <hr> <table width="100%" border="0" cellspacing="0" cellpadding="0">   <tr>     <td><a href="exportoutofstockfile.php">Out of stock:</a></td>     <td><a href="exportlowstockfile.php">Low stock:</a></td>     <td><a href="exportwarningstockfile.php">Stock running low:</a></td>    <td><a href="printstocksheet.php">Print stock sheet</a></td>   </tr> </table>   <script> function CheckShowBrandByBrand() {    form = window.document.frmByBrand;        if (form.sltBrand.selectedIndex == 0)    {       alert('You have not selected a brand to view details!');       return false;       }    else    {    return true;    } }  function CheckShowBrandByCategory() {    form = window.document.frmByCategory;        if (form.sltCategory.selectedIndex == 0)    {       alert('You have not selected a Category to view details!');       return false;       }    else    {    return true;    } }  function CheckShowBrandBySearch() {    form = window.document.frmSearchBrand;        if (form.txtSearchBrand.value == "")    {       alert('You have not entered a brand name to search!');       return false;       }    else    {    return true;    } } </script>
But you can see that page has one function so the pagination works well using the variable ($page)

My problem is how to make it work in a page containing multiple functions AND it works in every function
Where should I change without having to make a pagination function for every POST function

My page of functions where I want to use it below:

Expand|Select|Wrap|Line Numbers
  1. <? require_once '../../functions.php';    $_SESSION['login_return_url'] = $_SERVER['REQUEST_URI']; checkUser();  $action = isset($_GET['action']) ? $_GET['action'] : ''; //$page = $_GET['action'];  switch ($action) {    case 'jan' :       sales_January();    break;           case 'feb' :       sales_February();    break;        case 'mar' :       sales_March();    break;           case 'april' :       sales_April();    break;        case 'may' :       sales_May();    break;           case 'june' :       sales_June();    break;        case 'july' :       sales_July();    break;           case 'aug' :       sales_August();    break;        case 'sept' :       sales_September();    break;           case 'oct' :       sales_October();    break;        case 'nov' :       sales_November();    break;           case 'dec' :       sales_December();    break;           case 'allsalestoday' :       allsales_Today();    break;           case 'allsalessevendays' :       allsales_SevenDays();    break;        case 'salesbycategory' :       salesbyCategory();    break;        case 'salesbybrand' :       salesbyBrand();    break;     default : }  function allsales_Today($action) {    $rowsPerPage = 2;     //$sql = 'SELECT * FROM cstocksales WHERE SaleDate = current_date';    $sql = 'SELECT * FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= SaleDate';        //$result = dbQuery($sql);    $result     = dbQuery(getPagingQuery($sql, $rowsPerPage));    $pagingLink = getPagingLink($sql, $rowsPerPage);        if (dbNumRows($result) == 0) //if none       {         echo '<p><font color=#CC0000><h4>No sales for today were found in the records...</h4></font></p>';       echo 'Go back <a href="index.php">Here</a> for another search.';    }    else    {       echo "<h5>Today's sales sales:<p></h5>";       echo '<table width="100%"  border="1" bordercolor="#000000">';      echo'<tr>';       echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';       echo'<th scope="col" bgcolor="#66FFFF">Category</th>';       echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';       echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';       echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';       echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';       echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';     echo'</tr>';      while($row = dbFetchArray($result))     // while($row = mysql_fetch_array($result))      {                 echo'<tr>';          echo'<td align="center">';          $SaleID = $row["SaleID"];                   echo $SaleID. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Category = $row["Category"];                   echo $Category. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Brand = $row["Brand"];                   echo $Brand. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Quantity = $row["Quantity"];                   echo $Quantity. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $PaidBy = $row["PaidBy"];                   echo $PaidBy. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Cost = $row["Cost"];                   echo $Cost. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $SaleDate = $row["SaleDate"];                   echo $SaleDate. "<br>";                   echo'</td align="center">';                   echo '</tr>';              }    echo'</table>';        //paginating link    echo $pagingLink;        echo "<br>"; echo "<strong>Sales figures:</strong>"; echo "<hr>";        $sql_total = 'SELECT PaidBy, SUM(Cost) FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= SaleDate GROUP BY PaidBy';        $result = dbQuery($sql_total);             while($row = dbFetchArray($result))         {        echo "Total sales by ". $row['PaidBy']. "<font color=#CC0000> =  Kshs <strong>". $row['SUM(Cost)']; echo "</font></strong>";       echo "&nbsp;&nbsp;"; echo"|"; echo "&nbsp;&nbsp;";       }           $sql_total_final = 'SELECT SUM(Cost) FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= SaleDate';        $result = dbQuery($sql_total_final);    while($row = dbFetchArray($result))         {       echo "<strong>All sales = <font color=#CC0000> Kshs " .$row['SUM(Cost)']; echo "</font></strong>" ;       }    }     echo "<br>";    echo '<h4><a href="index.php">Back</a> to sales panel.'; }  function allsales_SevenDays() {    $sql = 'SELECT * FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL 8 DAY) <= SaleDate';       $result = dbQuery($sql);    ///$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));    //$pagingLink = getPagingLink($sql, $rowsPerPage);        if (dbNumRows($result) == 0) //if none       {         echo '<p><font color=#CC0000><h4>No sales for the past seven days were found in the records...</h4></font></p>';       echo 'Go back <a href="index.php">Here</a> for another search.';    }    else    {       echo '<h5>Sales in the past seven days:<p></h5>';       echo '<table width="100%"  border="1" bordercolor="#000000">';      echo'<tr>';       echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';       echo'<th scope="col" bgcolor="#66FFFF">Category</th>';       echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';       echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';       echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';       echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';       echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';     echo'</tr>';      while($row = dbFetchArray($result))      {        echo'<tr>';          echo'<td align="center">';          $SaleID = $row["SaleID"];                   echo $SaleID. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Category = $row["Category"];                   echo $Category. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Brand = $row["Brand"];                   echo $Brand. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Quantity = $row["Quantity"];                   echo $Quantity. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $PaidBy = $row["PaidBy"];                   echo $PaidBy. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Cost = $row["Cost"];                   echo $Cost. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $SaleDate = $row["SaleDate"];                   echo $SaleDate. "<br>";                   echo'</td align="center">';                   echo '</tr>';      }    echo'</table>';    //    echo 'Go back <a href="index.php">Here</a> for another search.';    } }   ///////////////////////////// function salesbyCategory() {    $byCategory = $_POST['sltCategory'];        $sql = 'SELECT * FROM cstocksales WHERE Category = "'.$byCategory.'"';        $result = dbQuery($sql);    ///$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));    //$pagingLink = getPagingLink($sql, $rowsPerPage);        if (dbNumRows($result) == 0) //if none       {         echo '<p><font color=#CC0000><h4>No sales for the Category "'.$_POST['sltCategory'].'" were found in the records...</h4></font></p>';       echo 'Go back <a href="index.php">Here</a> for another search.';    }    else    {       echo '<h5>"'.$_POST['sltCategory'].'" sales:<p></h5>';       echo '<table width="100%"  border="1" bordercolor="#000000">';      echo'<tr>';       echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';       echo'<th scope="col" bgcolor="#66FFFF">Category</th>';       echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';       echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';       echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';       echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';       echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';     echo'</tr>';      while($row = dbFetchArray($result))      {        echo'<tr>';          echo'<td align="center">';          $SaleID = $row["SaleID"];                   echo $SaleID. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Category = $row["Category"];                   echo $Category. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Brand = $row["Brand"];                   echo $Brand. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Quantity = $row["Quantity"];                   echo $Quantity. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $PaidBy = $row["PaidBy"];                   echo $PaidBy. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Cost = $row["Cost"];                   echo $Cost. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $SaleDate = $row["SaleDate"];                   echo $SaleDate. "<br>";                   echo'</td align="center">';                   echo '</tr>';      }    echo'</table>';    echo 'Go back <a href="index.php">Here</a> for another search.';    } }  function salesbyBrand() {    $byBrand = $_POST['sltBrand'];        $sql = 'SELECT * FROM cstocksales WHERE Brand = "'.$byBrand.'"';        $result = dbQuery($sql);    ///$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));    //$pagingLink = getPagingLink($sql, $rowsPerPage);        if (dbNumRows($result) == 0) //if none       {         echo '<p><font color=#CC0000><h4>No sales for the brand  "'.$_POST['sltBrand'].'" were found in the records...</h4></font></p>';       echo 'Go back <a href="index.php">Here</a> for another search.';    }    else    {       echo '<h5>"'.$_POST['sltBrand'].'" slaes:<p></h5>';       echo '<table width="100%"  border="1" bordercolor="#000000">';      echo'<tr>';       echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';       echo'<th scope="col" bgcolor="#66FFFF">Category</th>';       echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';       echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';       echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';       echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';       echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';     echo'</tr>';      while($row = dbFetchArray($result))      {        echo'<tr>';          echo'<td align="center">';          $SaleID = $row["SaleID"];                   echo $SaleID. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Category = $row["Category"];                   echo $Category. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Brand = $row["Brand"];                   echo $Brand. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Quantity = $row["Quantity"];                   echo $Quantity. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $PaidBy = $row["PaidBy"];                   echo $PaidBy. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $Cost = $row["Cost"];                   echo $Cost. "<br>";                   echo'</td align="center">';          echo'<td align="center">';          $SaleDate = $row["SaleDate"];                   echo $SaleDate. "<br>";                   echo'</td align="center">';                   echo '</tr>';      }    echo'</table>';        echo 'Go back <a href="index.php">Here</a> for another search.';    } } ?>


I hope I provided clear information...
Oct 7 '08 #1
16 2740
code green
1,726 Expert 1GB
I would forget about your immediate problem and redsign the whole thing.
Are you a self taught programmer?.
I ask because you have developed an unorthordox style.

There is surely no need for one function per month.
The correct way would be one function and pass the month as a parameter.

A function should perform one function not be used as a dump for a mishmash of SQL PHP and HTML

I may be misjudging because I cannot read your code comfortably..
How did you manage to get it all on one line?
Oct 7 '08 #2
gnawz
64
Yes,
I'm a self taught programmer.

I have a drop-down from which one selects to view month (passed as a parameter)

I broke it down just so that one can understand what I mean by having many function but want the same pagination function to work in each.

I copied the code and pasted it.

When you look at my pagination code and my post, how would I use the pagination in a page containing a series of functions?

I would forget about your immediate problem and redesign the whole thing.
Are you a self taught programmer?.
I ask because you have developed an unorthordox style.

There is surely no need for one function per month.
The correct way would be one function and pass the month as a parameter.

A function should perform one function not be used as a dump for a mishmash of SQL PHP and HTML

I may be misjudging because I cannot read your code comfortably..
How did you manage to get it all on one line?
Oct 7 '08 #3
code green
1,726 Expert 1GB
I am sorry. I have tried but cannot read your code in its present format.

Any chance of a moderator stepping in and advising gnawz on what he has done to make his code so unreadable.

I am referring only to the layout within the forum.
All on one line and a proliferation of spaces
Oct 7 '08 #4
Markus
6,050 Expert 4TB
I am sorry. I have tried but cannot read your code in its present format.

Any chance of a moderator stepping in and advising gnawz on what he has done to make his code so unreadable.

I am referring only to the layout within the forum.
All on one line and a proliferation of spaces
I attempted to format the code, but there's a hell of a lot and I don't have the time.

Gnawz, when you post code in the forums, please format it with indents and new lines so we here can actually read it.

ps: maybe format the code you gave previously and post it again so people can look at it better.
Oct 7 '08 #5
gnawz
64
Dear all,

I have re-posted this thread with my code outside code tags as they are difficult to edit and mess all the code

I have a pagination function in function.php

Expand|Select|Wrap|Line Numbers
  1. <?
  2. //Pagination functions
  3.  
  4. function getPagingQuery($sql, $itemPerPage = 10)
  5. {
  6.    if (isset($_GET['page']) && (int)$_GET['page'] > 0)
  7.    {
  8.       $page = (int)$_GET['page'];
  9.    }
  10.    else
  11.    {
  12.       $page = 1;
  13.    }
  14.  
  15.    // start fetching from this row number
  16.    $offset = ($page - 1) * $itemPerPage;
  17.  
  18.    return $sql . " LIMIT $offset, $itemPerPage";
  19. }
  20.  
  21. /*
  22.    Get the links to navigate between one result page to another.
  23.  
  24. */
  25.  
  26.  
  27. function getPagingLink($sql, $itemPerPage = 10, $strGet = '')
  28. {
  29.    $result        = dbQuery($sql);
  30.    $pagingLink    = '';
  31.    $totalResults  = dbNumRows($result);
  32.    $totalPages    = ceil($totalResults / $itemPerPage);
  33.  
  34.    // how many link pages to show
  35.    $numLinks      = 10;
  36.  
  37.  
  38.    // create the paging links only if theres more than one page of results
  39.    if ($totalPages > 1) {
  40.  
  41.       $self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ;
  42.  
  43.  
  44.       if (isset($_GET['page']) && (int)$_GET['page'] > 0) {
  45.          $pageNumber = (int)$_GET['page'];
  46.       } else {
  47.          $pageNumber = 1;
  48.       }
  49.  
  50.       // print 'previous' link only if its not
  51.       // on page one
  52.       if ($pageNumber > 1) {
  53.          $page = $pageNumber - 1;
  54.          if ($page > 1) {
  55.             $prev = " <a href=\"$self?page=$page&$strGet/\">[Prev]</a> ";
  56.             ||
  57.             $prev = " <a href=\"$self?action=$action&$strGet/\">[Prev]</a> ";
  58.          } else {
  59.             $prev = " <a href=\"$self?$strGet\">[Prev]</a> ";
  60.          }   
  61.  
  62.          $first = " <a href=\"$self?$strGet\">[First]</a> ";
  63.       } else {
  64.          $prev  = ''; // on page one, don't show 'previous' link
  65.          $first = ''; // nor 'first page' link
  66.       }
  67.  
  68.       // print 'next' link only if its not
  69.       // on the last page
  70.       if ($pageNumber < $totalPages) {
  71.          $page = $pageNumber + 1;
  72.          $next = " <a href=\"$self?page=$page&$strGet\">[Next]</a> "; || " <a href=\"$self?action=$action&$strGet/\">[Prev]</a> ";
  73.          $last = " <a href=\"$self?page=$totalPages&$strGet\">[Last]</a> "; || " <a href=\"$self?action=$action&$strGet/\">[Prev]</a> ";
  74.       } else {
  75.          $next = ''; // if on the last page, don't show 'next' link
  76.          $last = ''; // nor 'last page' link
  77.       }
  78.  
  79.       $start = $pageNumber - ($pageNumber % $numLinks) + 1;
  80.       $end   = $start + $numLinks - 1;      
  81.  
  82.       $end   = min($totalPages, $end);
  83.  
  84.       $pagingLink = array();
  85.       for($page = $start; $page <= $end; $page++)   {
  86.          if ($page == $pageNumber) {
  87.             $pagingLink[] = " $page ";   // no need to create a link to current page
  88.          } else {
  89.             if ($page == 1) {
  90.                $pagingLink[] = " <a href=\"$self?$strGet\">$page</a> ";
  91.             } else {   
  92.                $pagingLink[] = " <a href=\"$self?page=$page&$strGet\">$page</a> ";
  93.             }   
  94.          }
  95.  
  96.       }
  97.  
  98.       $pagingLink = implode(' | ', $pagingLink);
  99.  
  100.       // return the page navigation link
  101.       $pagingLink = $first . $prev . $pagingLink . $next . $last;
  102.    }
  103.  
  104.    return $pagingLink;
  105. }
  106. ?>
  107.  
  108. I have used it in  this page (list.php)
  109.  
  110. <?php
  111. if (!defined('WEB_ROOT')) {
  112.    exit;
  113. }
  114. $rowsPerPage = 5;
  115.  
  116. $_SESSION['login_return_url'] = $_SERVER['REQUEST_URI'];
  117. checkUser();
  118.  
  119. $sql = "SELECT * FROM fragrancestock";
  120. $result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
  121. $pagingLink = getPagingLink($sql, $rowsPerPage);
  122.  
  123. $errorMessage = (isset($_GET['cstock_error']) && $_GET['cstock_error'] != '') ? $_GET['cstock_error'] : '&nbsp;';
  124. ?>
  125. <form action="index.php?view=add" method="post"  name="frmList" id="frmList">
  126.   <table width="100%" border="0" align="center">
  127.     <tr class="title_text">
  128.       <td width="100">Category</td>
  129.       <td width="400">Brand</td>
  130.       <td width="100" align="center">Stock</td>
  131.       <td width="100">Date Added</td>
  132.       <td width="50">Details</td>
  133.       <td width="50">Add</td>
  134.       <td width="50">Delete</td>
  135.     </tr>
  136.     <?php
  137. if (dbNumRows($result) > 0) {
  138.    $i = 0;
  139.  
  140.    while($row = dbFetchAssoc($result)) {
  141.       extract($row);
  142.  
  143.       if ($i%2) {
  144.          $class = 'row1';
  145.       } else {
  146.          $class = 'row2';
  147.       }
  148.  
  149.       $i += 1;
  150. ?>
  151.     <tr class="<?php echo $class; ?>">
  152.       <td width="100"><?php echo $Category; ?></td>
  153.       <td width="400"><?php echo $Brand; ?></td>
  154.       <td width="100" class="inner_border"><?php echo $Quantity; ?></td>
  155.       <td width="100"><?php echo $DateAddedStock; ?></td>
  156.       <td width="50"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?view=detail&StockID=<?php echo $StockID; ?>">View</a></td>
  157.       <td width="50"><a href="javascript:modifyStock(<?php echo $StockID; ?>);"><strong>Add
  158.         </strong> </a></td>
  159.       <td width="50"><a href="javascript:deleteStock(<?php echo $StockID; ?>);">Delete</a></td>
  160.     </tr>
  161.     <?php
  162.    } // end while
  163.  
  164.  
  165. ?>
  166.     <tr>
  167.       <td colspan="7" align="center">
  168.         <?php 
  169.    echo $pagingLink;
  170.    ?>
  171.       </td>
  172.     </tr>
  173.     <?php   
  174. } else {
  175. ?>
  176.     <tr>
  177.       <td colspan="7" align="center">No Stock Items Yet</td>
  178.     </tr>
  179.     <?php
  180. }
  181. ?>
  182.     <tr>
  183.       <td colspan="7">&nbsp;</td>
  184.     </tr>
  185.     <tr>
  186.       <td colspan="7" align="right"> <input name="btnAddStock" type="submit" value="New Entry" class="button_image">
  187.     </tr>
  188.   </table>
  189. </form>
  190.  
  191. <label class="title_text">View Stock:</label>
  192. <hr>
  193. <table width="100%" border="0">
  194.   <tr>
  195.     <td><form action="index.php?view=showbybrand" method="post" name="frmByBrand">
  196.         <table width="100%" border="0">
  197.           <tr>
  198.             <td width="200">By Brand:</td>
  199.             <td width="200"><select name="sltBrand">
  200.                 <option value="0">Select Brand</option>
  201.                 <?
  202.          $sql = "SELECT DISTINCT Brand FROM cstockitems ORDER BY Brand ASC";
  203.          $result = dbQuery($sql);      
  204.  
  205.          if(dbNumRows($result))
  206.          {
  207.             while($row = dbFetchAssoc($result))
  208.             {
  209.             echo "<option>$row[Brand]</option>";
  210.             }
  211.          }
  212.                 else
  213.                {
  214.             echo "<option>No Brands Present</option>";
  215.                }
  216.      ?>
  217.               </select></td>
  218.             <td width="200"><input type="submit" name="Submit" value="Show" class="button_image" onClick="return CheckShowBrandByBrand();">
  219.             </td>
  220.           </tr>
  221.         </table>
  222.       </form></td>
  223.   </tr>
  224.   <tr>
  225.     <td><form name="frmByCategory" method="post" action="showbycategory.php">
  226.         <table width="100%" border="0">
  227.           <tr>
  228.             <td width="200">By Category:</td>
  229.             <td width="200"><select name="sltCategory">
  230.                 <option value="0">Select Category</option>
  231.                 <?
  232.          $sql = "SELECT DISTINCT Category FROM cstockitems ORDER BY Category ASC";
  233.          $result = dbQuery($sql);      
  234.  
  235.          if(dbNumRows($result))
  236.          {
  237.             while($row = dbFetchAssoc($result))
  238.             {
  239.             echo "<option>$row[Category]</option>";
  240.             }
  241.          }
  242.                 else
  243.                {
  244.             echo "<option>No Categories Present</option>";
  245.                }
  246.      ?>
  247.               </select></td>
  248.             <td width="200"><input type="submit" name="Submit2" value="Show" class="button_image" onClick="return CheckShowBrandByCategory();"></td>
  249.           </tr>
  250.         </table>
  251.       </form></td>
  252.   </tr>
  253.   <tr>
  254.     <td><form name="frmSearchBrand" method="post" action="showbysearch.php">
  255.         <table width="100%" border="0">
  256.           <tr>
  257.             <td width="200">Search:</td>
  258.             <td width="200"><input type="text" name="txtSearchBrand" size="40"></td>
  259.             <td width="200"><input type="submit" name="Submit3" value="Search" class="button_image" onClick="return CheckShowBrandBySearch();"></td>
  260.           </tr>
  261.         </table>
  262.       </form></td>
  263.   </tr>
  264. </table>
  265. <label class="title_text">Print product list for re-stocking:</label>
  266. <hr>
  267. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  268.   <tr>
  269.     <td><a href="exportoutofstockfile.php">Out of stock:</a></td>
  270.     <td><a href="exportlowstockfile.php">Low stock:</a></td>
  271.     <td><a href="exportwarningstockfile.php">Stock running low:</a></td>
  272.    <td><a href="printstocksheet.php">Print stock sheet</a></td>
  273.   </tr>
  274. </table>
  275.  
  276.  
  277. <script>
  278. function CheckShowBrandByBrand()
  279. {
  280.    form = window.document.frmByBrand;
  281.  
  282.    if (form.sltBrand.selectedIndex == 0)
  283.    {
  284.       alert('You have not selected a brand to view details!');
  285.       return false;   
  286.    }
  287.    else
  288.    {
  289.    return true;
  290.    }
  291. }
  292.  
  293. function CheckShowBrandByCategory()
  294. {
  295.    form = window.document.frmByCategory;
  296.  
  297.    if (form.sltCategory.selectedIndex == 0)
  298.    {
  299.       alert('You have not selected a Category to view details!');
  300.       return false;   
  301.    }
  302.    else
  303.    {
  304.    return true;
  305.    }
  306. }
  307.  
  308. function CheckShowBrandBySearch()
  309. {
  310.    form = window.document.frmSearchBrand;
  311.  
  312.    if (form.txtSearchBrand.value == "")
  313.    {
  314.       alert('You have not entered a brand name to search!');
  315.       return false;   
  316.    }
  317.    else
  318.    {
  319.    return true;
  320.    }
  321. }
  322. </script>
  323. <?
  324. ?>
and it has worked well.

However, I need help on how to use it in a page with multiple functions as below

Expand|Select|Wrap|Line Numbers
  1. <?
  2. require_once '../../functions.php';
  3.  
  4.  
  5. $_SESSION['login_return_url'] = $_SERVER['REQUEST_URI'];
  6. checkUser();
  7.  
  8. $action = isset($_GET['action']) ? $_GET['action'] : '';
  9. //$page = $_GET['action'];
  10.  
  11. switch ($action)
  12. {
  13.       case 'allsalestoday' :
  14.       allsales_Today();
  15.    break;
  16.  
  17.       case 'allsalessevendays' :
  18.       allsales_SevenDays();
  19.    break;
  20.  
  21.    case 'salesbycategory' :
  22.       salesbyCategory();
  23.    break;
  24.  
  25.    case 'salesbybrand' :
  26.       salesbyBrand();
  27.    break;
  28.  
  29. default :
  30. }
  31.  
  32. $_SESSION['login_return_url'] = $_SERVER['REQUEST_URI'];
  33. checkUser();
  34.  
  35. $action = isset($_GET['action']) ? $_GET['action'] : '';
  36. //$page = $_GET['action'];
  37.  
  38. switch ($action)
  39. {
  40.  
  41.  
  42. default :
  43. }
  44.  
  45. function allsales_Today($action)
  46. {
  47.    $rowsPerPage = 2;
  48.  
  49.    //$sql = 'SELECT * FROM cstocksales WHERE SaleDate = current_date';
  50.    $sql = 'SELECT * FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= SaleDate';
  51.  
  52.    //$result = dbQuery($sql);
  53.    $result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
  54.    $pagingLink = getPagingLink($sql, $rowsPerPage);
  55.  
  56.    if (dbNumRows($result) == 0) //if none   
  57.    {
  58.         echo '<p><font color=#CC0000><h4>No sales for today were found in the records...</h4></font></p>';
  59.       echo 'Go back <a href="index.php">Here</a> for another search.';
  60.    }
  61.    else
  62.    {
  63.       echo "<h5>Today's sales sales:<p></h5>";
  64.       echo '<table width="100%"  border="1" bordercolor="#000000">';
  65.      echo'<tr>';
  66.       echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';
  67.       echo'<th scope="col" bgcolor="#66FFFF">Category</th>';
  68.       echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';
  69.       echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';
  70.       echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';
  71.       echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';
  72.       echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';
  73.     echo'</tr>';
  74.      while($row = dbFetchArray($result))
  75.     // while($row = mysql_fetch_array($result))
  76.      {
  77.  
  78.        echo'<tr>';
  79.          echo'<td align="center">';
  80.          $SaleID = $row["SaleID"];
  81.                   echo $SaleID. "<br>";
  82.                   echo'</td align="center">';
  83.          echo'<td align="center">';
  84.          $Category = $row["Category"];
  85.                   echo $Category. "<br>";
  86.                   echo'</td align="center">';
  87.          echo'<td align="center">';
  88.          $Brand = $row["Brand"];
  89.                   echo $Brand. "<br>";
  90.                   echo'</td align="center">';
  91.          echo'<td align="center">';
  92.          $Quantity = $row["Quantity"];
  93.                   echo $Quantity. "<br>";
  94.                   echo'</td align="center">';
  95.          echo'<td align="center">';
  96.          $PaidBy = $row["PaidBy"];
  97.                   echo $PaidBy. "<br>";
  98.                   echo'</td align="center">';
  99.          echo'<td align="center">';
  100.          $Cost = $row["Cost"];
  101.                   echo $Cost. "<br>";
  102.                   echo'</td align="center">';
  103.          echo'<td align="center">';
  104.          $SaleDate = $row["SaleDate"];
  105.                   echo $SaleDate. "<br>";
  106.                   echo'</td align="center">';
  107.  
  108.         echo '</tr>';
  109.  
  110.      }
  111.    echo'</table>';
  112.  
  113.    //paginating link
  114.    echo $pagingLink;
  115.  
  116.    echo "<br>"; echo "<strong>Sales figures:</strong>"; echo "<hr>";
  117.  
  118.    $sql_total = 'SELECT PaidBy, SUM(Cost) FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= SaleDate GROUP BY PaidBy';
  119.  
  120.    $result = dbQuery($sql_total);
  121.  
  122.  
  123.  
  124.    while($row = dbFetchArray($result))
  125.         {
  126.        echo "Total sales by ". $row['PaidBy']. "<font color=#CC0000> =  Kshs <strong>". $row['SUM(Cost)']; echo "</font></strong>";
  127.       echo "&nbsp;&nbsp;"; echo"|"; echo "&nbsp;&nbsp;";
  128.       }
  129.  
  130.    $sql_total_final = 'SELECT SUM(Cost) FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= SaleDate';
  131.  
  132.    $result = dbQuery($sql_total_final);
  133.    while($row = dbFetchArray($result))
  134.         {
  135.       echo "<strong>All sales = <font color=#CC0000> Kshs " .$row['SUM(Cost)']; echo "</font></strong>" ;
  136.       }
  137.    }
  138.  
  139.    echo "<br>";
  140.    echo '<h4><a href="index.php">Back</a> to sales panel.';
  141. }
  142.  
  143. function allsales_SevenDays()
  144. {
  145.    $sql = 'SELECT * FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL 8 DAY) <= SaleDate';   
  146.    $result = dbQuery($sql);
  147.    ///$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
  148.    //$pagingLink = getPagingLink($sql, $rowsPerPage);
  149.  
  150.    if (dbNumRows($result) == 0) //if none   
  151.    {
  152.         echo '<p><font color=#CC0000><h4>No sales for the past seven days were found in the records...</h4></font></p>';
  153.       echo 'Go back <a href="index.php">Here</a> for another search.';
  154.    }
  155.    else
  156.    {
  157.       echo '<h5>Sales in the past seven days:<p></h5>';
  158.       echo '<table width="100%"  border="1" bordercolor="#000000">';
  159.      echo'<tr>';
  160.       echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';
  161.       echo'<th scope="col" bgcolor="#66FFFF">Category</th>';
  162.       echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';
  163.       echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';
  164.       echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';
  165.       echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';
  166.       echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';
  167.     echo'</tr>';
  168.      while($row = dbFetchArray($result))
  169.      {
  170.        echo'<tr>';
  171.          echo'<td align="center">';
  172.          $SaleID = $row["SaleID"];
  173.                   echo $SaleID. "<br>";
  174.                   echo'</td align="center">';
  175.          echo'<td align="center">';
  176.          $Category = $row["Category"];
  177.                   echo $Category. "<br>";
  178.                   echo'</td align="center">';
  179.          echo'<td align="center">';
  180.          $Brand = $row["Brand"];
  181.                   echo $Brand. "<br>";
  182.                   echo'</td align="center">';
  183.          echo'<td align="center">';
  184.          $Quantity = $row["Quantity"];
  185.                   echo $Quantity. "<br>";
  186.                   echo'</td align="center">';
  187.          echo'<td align="center">';
  188.          $PaidBy = $row["PaidBy"];
  189.                   echo $PaidBy. "<br>";
  190.                   echo'</td align="center">';
  191.          echo'<td align="center">';
  192.          $Cost = $row["Cost"];
  193.                   echo $Cost. "<br>";
  194.                   echo'</td align="center">';
  195.          echo'<td align="center">';
  196.          $SaleDate = $row["SaleDate"];
  197.                   echo $SaleDate. "<br>";
  198.                   echo'</td align="center">';
  199.  
  200.         echo '</tr>';
  201.      }
  202.    echo'</table>';
  203.    //
  204.    echo 'Go back <a href="index.php">Here</a> for another search.';
  205.    }
  206. }
  207.  
  208.  
  209. /////////////////////////////
  210. function salesbyCategory()
  211. {
  212.    $byCategory = $_POST['sltCategory'];
  213.  
  214.    $sql = 'SELECT * FROM cstocksales WHERE Category = "'.$byCategory.'"';
  215.  
  216.    $result = dbQuery($sql);
  217.    ///$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
  218.    //$pagingLink = getPagingLink($sql, $rowsPerPage);
  219.  
  220.    if (dbNumRows($result) == 0) //if none   
  221.    {
  222.         echo '<p><font color=#CC0000><h4>No sales for the Category "'.$_POST['sltCategory'].'" were found in the records...</h4></font></p>';
  223.       echo 'Go back <a href="index.php">Here</a> for another search.';
  224.    }
  225.    else
  226.    {
  227.       echo '<h5>"'.$_POST['sltCategory'].'" sales:<p></h5>';
  228.       echo '<table width="100%"  border="1" bordercolor="#000000">';
  229.      echo'<tr>';
  230.       echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';
  231.       echo'<th scope="col" bgcolor="#66FFFF">Category</th>';
  232.       echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';
  233.       echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';
  234.       echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';
  235.       echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';
  236.       echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';
  237.     echo'</tr>';
  238.      while($row = dbFetchArray($result))
  239.      {
  240.        echo'<tr>';
  241.          echo'<td align="center">';
  242.          $SaleID = $row["SaleID"];
  243.                   echo $SaleID. "<br>";
  244.                   echo'</td align="center">';
  245.          echo'<td align="center">';
  246.          $Category = $row["Category"];
  247.                   echo $Category. "<br>";
  248.                   echo'</td align="center">';
  249.          echo'<td align="center">';
  250.          $Brand = $row["Brand"];
  251.                   echo $Brand. "<br>";
  252.                   echo'</td align="center">';
  253.          echo'<td align="center">';
  254.          $Quantity = $row["Quantity"];
  255.                   echo $Quantity. "<br>";
  256.                   echo'</td align="center">';
  257.          echo'<td align="center">';
  258.          $PaidBy = $row["PaidBy"];
  259.                   echo $PaidBy. "<br>";
  260.                   echo'</td align="center">';
  261.          echo'<td align="center">';
  262.          $Cost = $row["Cost"];
  263.                   echo $Cost. "<br>";
  264.                   echo'</td align="center">';
  265.          echo'<td align="center">';
  266.          $SaleDate = $row["SaleDate"];
  267.                   echo $SaleDate. "<br>";
  268.                   echo'</td align="center">';
  269.  
  270.         echo '</tr>';
  271.      }
  272.    echo'</table>';
  273.    echo 'Go back <a href="index.php">Here</a> for another search.';
  274.    }
  275. }
  276.  
  277. function salesbyBrand()
  278. {
  279.    $byBrand = $_POST['sltBrand'];
  280.  
  281.    $sql = 'SELECT * FROM cstocksales WHERE Brand = "'.$byBrand.'"';
  282.  
  283.    $result = dbQuery($sql);
  284.    ///$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
  285.    //$pagingLink = getPagingLink($sql, $rowsPerPage);
  286.  
  287.    if (dbNumRows($result) == 0) //if none   
  288.    {
  289.         echo '<p><font color=#CC0000><h4>No sales for the brand  "'.$_POST['sltBrand'].'" were found in the records...</h4></font></p>';
  290.       echo 'Go back <a href="index.php">Here</a> for another search.';
  291.    }
  292.    else
  293.    {
  294.       echo '<h5>"'.$_POST['sltBrand'].'" slaes:<p></h5>';
  295.       echo '<table width="100%"  border="1" bordercolor="#000000">';
  296.      echo'<tr>';
  297.       echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';
  298.       echo'<th scope="col" bgcolor="#66FFFF">Category</th>';
  299.       echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';
  300.       echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';
  301.       echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';
  302.       echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';
  303.       echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';
  304.     echo'</tr>';
  305.      while($row = dbFetchArray($result))
  306.      {
  307.        echo'<tr>';
  308.          echo'<td align="center">';
  309.          $SaleID = $row["SaleID"];
  310.                   echo $SaleID. "<br>";
  311.                   echo'</td align="center">';
  312.          echo'<td align="center">';
  313.          $Category = $row["Category"];
  314.                   echo $Category. "<br>";
  315.                   echo'</td align="center">';
  316.          echo'<td align="center">';
  317.          $Brand = $row["Brand"];
  318.                   echo $Brand. "<br>";
  319.                   echo'</td align="center">';
  320.          echo'<td align="center">';
  321.          $Quantity = $row["Quantity"];
  322.                   echo $Quantity. "<br>";
  323.                   echo'</td align="center">';
  324.          echo'<td align="center">';
  325.          $PaidBy = $row["PaidBy"];
  326.                   echo $PaidBy. "<br>";
  327.                   echo'</td align="center">';
  328.          echo'<td align="center">';
  329.          $Cost = $row["Cost"];
  330.                   echo $Cost. "<br>";
  331.                   echo'</td align="center">';
  332.          echo'<td align="center">';
  333.          $SaleDate = $row["SaleDate"];
  334.                   echo $SaleDate. "<br>";
  335.                   echo'</td align="center">';
  336.  
  337.         echo '</tr>';
  338.      }
  339.    echo'</table>';
  340.  
  341.    echo 'Go back <a href="index.php">Here</a> for another search.';
  342.    }
  343. }
  344. ?>
When I use it in functions that are contained in one page, I shows the first page but when I click next, it goes blank as it only recognises the page, not the function or action

Eg it shows this for page 2 which is blank....

http://localhost/cstock/admin/viewsa...es.php?page=2&

yet I would like it to show

http://localhost/cstock/admin/viewsa...stoday&page=2&

and so on... ie It should maintain the search action (function) in subsequent paginations.

Some body help
Oct 7 '08 #6
Markus
6,050 Expert 4TB
I won't give you a formal warning for not using code tags, as I believe you knowingly did it with the best intentions. But you must use code tags.
Oct 7 '08 #7
ak1dnar
1,584 Expert 1GB
Merged with duplicate thread (thread843785.html). Thanks
Oct 7 '08 #8
code green
1,726 Expert 1GB
This is an awful lot of code, and that is in both sense of the word awful.Nevertheless I cannot see where you have written the 'action' value in the URL.
that you are trying to read. [PHP]$action = isset($_GET['action']) ? $_GET['action'] : '';[/PHP]
But the code meanders and repeats itself so much it is too tiring to decipher.
I still stand by my first suggestion
Oct 7 '08 #9
pbmods
5,821 Expert 4TB
Hey, y'all. Please keep the unnecessary criticisms to a minimum and focus on solving the OP's problem.

We've all been beginners at one point or another; it's a stage everyone goes through, and code improves with experience.

gnawz, thanks for re-posting your code. I'll have a look at it shortly.
Oct 9 '08 #10
pbmods
5,821 Expert 4TB
Try passing 'action=allsalestoday' (etc.) as the third parameter to getPagingLink().

It looks like anything you put in the third parameter ($strGet) gets dumped right into the paging link.
Oct 9 '08 #11
gnawz
64
Thanks, Sir

I always get criticism here. We can not be perfect all at once.

I will try that and get back to you.
But remember, I do not want to create another pagination function-I want to use the same (single function) in all pages. I hope I can achieve that in this case.
I have also improved my code.
I will post again.


Try passing 'action=allsalestoday' (etc.) as the third parameter to getPagingLink().

It looks like anything you put in the third parameter ($strGet) gets dumped right into the paging link.
Oct 9 '08 #12
gnawz
64
The following is my pagination function which I use in pages with one function and it works well.
Expand|Select|Wrap|Line Numbers
  1. <?
  2. function getPagingQuery($sql, $itemPerPage = 10)
  3. {
  4.     if (isset($_GET['page']) && (int)$_GET['page'] > 0) 
  5.     {
  6.         $page = (int)$_GET['page'];
  7.     } 
  8.     else 
  9.     {
  10.         $page = 1;
  11.     }
  12.  
  13.     // start fetching from this row number
  14.     $offset = ($page - 1) * $itemPerPage;
  15.  
  16.     return $sql . " LIMIT $offset, $itemPerPage";
  17. }
  18.  
  19. /*
  20.     Get the links to navigate between one result page to another.
  21.  
  22. */
  23.  
  24.  
  25. function getPagingLink($sql, $itemPerPage = 10, $strGet = '')
  26. {
  27.     $result        = dbQuery($sql);
  28.     $pagingLink    = '';
  29.     $totalResults  = dbNumRows($result);
  30.     $totalPages    = ceil($totalResults / $itemPerPage);
  31.  
  32.     // how many link pages to show
  33.     $numLinks      = 10;
  34.  
  35.  
  36.     // create the paging links only if theres more than one page of results
  37.     if ($totalPages > 1) {
  38.  
  39.         $self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ;
  40.  
  41.  
  42.         if (isset($_GET['page']) && (int)$_GET['page'] > 0) {
  43.             $pageNumber = (int)$_GET['page'];
  44.         } else {
  45.             $pageNumber = 1;
  46.         }
  47.  
  48.         // print 'previous' link only if its not
  49.         // on page one
  50.         if ($pageNumber > 1) {
  51.             $page = $pageNumber - 1;
  52.             if ($page > 1) {
  53.                 $prev = " <a href=\"$self?page=$page&$strGet/\">[Prev]</a> ";
  54.             } else {
  55.                 $prev = " <a href=\"$self?$strGet\">[Prev]</a> ";
  56.             }    
  57.  
  58.             $first = " <a href=\"$self?$strGet\">[First]</a> ";
  59.         } else {
  60.             $prev  = ''; // on page one, don't show 'previous' link
  61.             $first = ''; // nor 'first page' link
  62.         }
  63.  
  64.         // print 'next' link only if its not
  65.         // on the last page
  66.         if ($pageNumber < $totalPages) {
  67.             $page = $pageNumber + 1;
  68.             $next = " <a href=\"$self?page=$page&$strGet\">[Next]</a> ";
  69.             $last = " <a href=\"$self?page=$totalPages&$strGet\">[Last]</a> ";
  70.         } else {
  71.             $next = ''; // if on the last page, don't show 'next' link
  72.             $last = ''; // nor 'last page' link
  73.         }
  74.  
  75.         $start = $pageNumber - ($pageNumber % $numLinks) + 1;
  76.         $end   = $start + $numLinks - 1;        
  77.  
  78.         $end   = min($totalPages, $end);
  79.  
  80.         $pagingLink = array();
  81.         for($page = $start; $page <= $end; $page++)    {
  82.             if ($page == $pageNumber) {
  83.                 $pagingLink[] = " $page ";   // no need to create a link to current page
  84.             } else {
  85.                 if ($page == 1) {
  86.                     $pagingLink[] = " <a href=\"$self?$strGet\">$page</a> ";
  87.                 } else {    
  88.                     $pagingLink[] = " <a href=\"$self?page=$page&$strGet\">$page</a> ";
  89.                 }    
  90.             }
  91.  
  92.         }
  93.  
  94.         $pagingLink = implode(' | ', $pagingLink);
  95.  
  96.         // return the page navigation link
  97.         $pagingLink = $first . $prev . $pagingLink . $next . $last;
  98.     }
  99.  
  100.     return $pagingLink;
  101. }
  102.  
I want to use it in each and every function of the following page.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3. require_once '../../functions.php';
  4.  
  5.  
  6.  
  7. $_SESSION['login_return_url'] = $_SERVER['REQUEST_URI'];
  8. checkUser();
  9.  
  10. $action = isset($_GET['action']) ? $_GET['action'] : '';
  11.  
  12. switch ($action) 
  13. {
  14.     case 'month' :
  15.         sales_Month();
  16.     break;
  17.  
  18.         case 'days' :
  19.         allsales_Day();
  20.  
  21.     case 'salesbybrand' :
  22.         salesbyBrand();
  23.     break;
  24.  
  25. default :
  26. }
  27.  
  28. function allsales_Day()
  29. {
  30.  
  31.     $day = '';
  32.     if (isset($_POST['sltallSales'])) $day = $_POST['sltallSales'];
  33.     elseif (isset($_GET['search'])) $day = $_GET['search'];
  34.  
  35.     $sql = "SELECT * FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL '$day' DAY) <= SaleDate";
  36.  
  37.     $result = dbQuery($sql, "search=$day");
  38.  
  39.     if (dbNumRows($result) == 0) //if none    
  40.     {
  41.           echo '<p><font color=#CC0000><h4>No sales were found in the records...</h4></font></p>';
  42.         echo '<h4><a href="index.php">Back</a> to sales panel.';
  43.     }
  44.     else
  45.     {
  46.         //echo "<h5>Today's sales:<p></h5>";
  47.         echo '<table width="100%"  border="1" bordercolor="#000000">';
  48.           echo'<tr>';
  49.         echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';
  50.         echo'<th scope="col" bgcolor="#66FFFF">Category</th>';
  51.         echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';
  52.         echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';
  53.         echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';
  54.         echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';
  55.         echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';
  56.          echo'</tr>';
  57.       while($row = dbFetchArray($result))
  58.      // while($row = mysql_fetch_array($result))
  59.       {
  60.  
  61.          echo'<tr>';
  62.             echo'<td align="center">';
  63.             $SaleID = $row["SaleID"];
  64.                         echo $SaleID. "<br>";
  65.                         echo'</td align="center">';
  66.             echo'<td align="center">';
  67.             $Category = $row["Category"];
  68.                         echo $Category. "<br>";
  69.                         echo'</td align="center">';
  70.             echo'<td align="center">';
  71.             $Brand = $row["Brand"];
  72.                         echo $Brand. "<br>";
  73.                         echo'</td align="center">';
  74.             echo'<td align="center">';
  75.             $Quantity = $row["Quantity"];
  76.                         echo $Quantity. "<br>";
  77.                         echo'</td align="center">';
  78.             echo'<td align="center">';
  79.             $PaidBy = $row["PaidBy"];
  80.                         echo $PaidBy. "<br>";
  81.                         echo'</td align="center">';
  82.             echo'<td align="center">';
  83.             $Cost = $row["Cost"];
  84.                         echo $Cost. "<br>";
  85.                         echo'</td align="center">';
  86.             echo'<td align="center">';
  87.             $SaleDate = $row["SaleDate"];
  88.                         echo $SaleDate. "<br>";
  89.                         echo'</td align="center">';
  90.  
  91.           echo '</tr>';
  92.  
  93.       }
  94.     echo'</table>';
  95.  
  96.     echo "<br>"; echo "<strong>Sales figures:</strong>"; echo "<hr>";
  97.  
  98.     $sql_total = "SELECT PaidBy, SUM(Cost) FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL '$day' DAY) <= SaleDate GROUP BY PaidBy";
  99.  
  100.     $result = dbQuery($sql_total);
  101.  
  102.  
  103.  
  104.     while($row = dbFetchArray($result))
  105.           {
  106.          echo "Total sales by ". $row['PaidBy']. "<font color=#CC0000> =  Kshs <strong>". $row['SUM(Cost)']; echo "</font></strong>";
  107.         echo "&nbsp;&nbsp;"; echo"|"; echo "&nbsp;&nbsp;";
  108.         }
  109.  
  110.     $sql_total_final = "SELECT SUM(Cost) FROM cstocksales WHERE DATE_SUB(CURDATE(),INTERVAL '$day' DAY) <= SaleDate";
  111.  
  112.     $result = dbQuery($sql_total_final);
  113.     while($row = dbFetchArray($result))
  114.           {
  115.         echo "<strong>All sales = <font color=#CC0000> Kshs " .$row['SUM(Cost)']; echo "</font></strong>" ;
  116.         }    
  117.  
  118.     echo "<br>"; 
  119.     echo '<h4><a href="index.php">Back</a> to sales panel.';
  120.     }
  121. }
  122.  
  123. function salesbyBrand()
  124. {
  125.     $byBrand = '';
  126.  
  127.     if (isset($_POST['sltBrand'])) $byBrand = $_POST['sltBrand'];
  128.     elseif (isset($_GET['search'])) $byBrand = $_GET['search'];
  129.  
  130.     $sql = "SELECT * FROM cstocksales WHERE Brand = '$byBrand'";
  131.  
  132.     $result = dbQuery($sql, "search=$byBrand");
  133.  
  134.     if (dbNumRows($result) == 0) //if none    
  135.     {
  136.           echo "<p><font color=#CC0000><h4>No sales for '$byBrand' were found in the records...</h4></font></p>";
  137.         echo "<h4><a href='index.php'>Back</a> to sales panel.";
  138.     }
  139.     else
  140.     {
  141.         echo '<h5>"'.$_POST['sltBrand'].'" slaes:<p></h5>';
  142.         echo '<table width="100%"  border="1" bordercolor="#000000">';
  143.           echo'<tr>';
  144.         echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';
  145.         echo'<th scope="col" bgcolor="#66FFFF">Category</th>';
  146.         echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';
  147.         echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';
  148.         echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';
  149.         echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';
  150.         echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';
  151.         echo'</tr>';
  152.  
  153.           while($row = dbFetchArray($result))
  154.           {
  155.              echo'<tr>';
  156.             echo'<td align="center">';
  157.             $SaleID = $row["SaleID"];
  158.                         echo $SaleID. "<br>";
  159.                         echo'</td align="center">';
  160.             echo'<td align="center">';
  161.             $Category = $row["Category"];
  162.                         echo $Category. "<br>";
  163.                         echo'</td align="center">';
  164.             echo'<td align="center">';
  165.             $Brand = $row["Brand"];
  166.                         echo $Brand. "<br>";
  167.                         echo'</td align="center">';
  168.             echo'<td align="center">';
  169.             $Quantity = $row["Quantity"];
  170.                         echo $Quantity. "<br>";
  171.                         echo'</td align="center">';
  172.             echo'<td align="center">';
  173.             $PaidBy = $row["PaidBy"];
  174.                         echo $PaidBy. "<br>";
  175.                         echo'</td align="center">';
  176.             echo'<td align="center">';
  177.             $Cost = $row["Cost"];
  178.                         echo $Cost. "<br>";
  179.                         echo'</td align="center">';
  180.             echo'<td align="center">';
  181.             $SaleDate = $row["SaleDate"];
  182.                         echo $SaleDate. "<br>";
  183.                         echo'</td align="center">';
  184.  
  185.           echo '</tr>';
  186.           }
  187.             echo'</table>';
  188.  
  189.             echo "<br>"; echo "<strong>Sales figures:</strong>"; echo "<hr>";
  190.  
  191.             $sql_total = "SELECT PaidBy, SUM(Cost) FROM cstocksales WHERE Brand = '$byBrand' GROUP BY PaidBy";
  192.  
  193.             $result = dbQuery($sql_total);
  194.  
  195.             while($row = dbFetchArray($result))
  196.               {
  197.             echo "Total sales by ". $row['PaidBy']. "<font color=#CC0000> =  Kshs <strong>". $row['SUM(Cost)']; echo "</font></strong>"    ;
  198.             echo "&nbsp;&nbsp;"; echo"|"; echo "&nbsp;&nbsp;";
  199.             }
  200.  
  201.             $sql_total_final = "SELECT SUM(Cost) FROM cstocksales WHERE Brand = '$byBrand'";
  202.  
  203.             $result = dbQuery($sql_total_final);
  204.             while($row = dbFetchArray($result))
  205.               {
  206.             echo "<strong>All sales = <font color=#CC0000> Kshs " .$row['SUM(Cost)']; echo "</font></strong>" ;
  207.             }
  208.  
  209.             echo "<br>"; 
  210.             echo '<h4><a href="index.php">Back</a> to sales panel.';
  211.     }
  212. }
  213.  
  214.  
  215. function sales_Month()
  216. {
  217.  
  218.     $month = $_POST['MonthSales'];
  219.  
  220.     $sql = "SELECT * FROM cstocksales WHERE MONTH(SaleDate) = '$month' AND YEAR(SaleDate) = YEAR(CURDATE())";
  221.  
  222.     $result = dbQuery($sql);
  223.     ///$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
  224.     //$pagingLink = getPagingLink($sql, $rowsPerPage);
  225.  
  226.     if (dbNumRows($result) == 0) //if none    
  227.     {
  228.           echo '<p><font color=#CC0000><h4>No sales were found in the records...</h4></font></p>';
  229.         echo '<h4><a href="index.php">Back</a> to sales panel.';
  230.     }
  231.     else
  232.     {
  233.         echo '<h5>January sales:<p></h5>';
  234.         echo '<table width="100%"  border="1" bordercolor="#000000">';
  235.           echo'<tr>';
  236.         echo'<th scope="col" bgcolor="#66FFFF">Sale No</th>';
  237.         echo'<th scope="col" bgcolor="#66FFFF">Category</th>';
  238.         echo'<th scope="col" bgcolor="#66FFFF">Brand</th>';
  239.         echo'<th scope="col" bgcolor="#66FFFF">Quantity </th>';
  240.         echo'<th scope="col" bgcolor="#66FFFF">Paid By: </th>';
  241.         echo'<th scope="col" bgcolor="#66FFFF">Amount </th>';
  242.         echo'<th scope="col" bgcolor="#66FFFF">Date of Sale </th>';
  243.      echo'</tr>';
  244.       while($row = dbFetchArray($result))
  245.       {
  246.          echo'<tr>';
  247.             echo'<td align="center">';
  248.             $SaleID = $row["SaleID"];
  249.                         echo $SaleID. "<br>";
  250.                         echo'</td align="center">';
  251.             echo'<td align="center">';
  252.             $Category = $row["Category"];
  253.                         echo $Category. "<br>";
  254.                         echo'</td align="center">';
  255.             echo'<td align="center">';
  256.             $Brand = $row["Brand"];
  257.                         echo $Brand. "<br>";
  258.                         echo'</td align="center">';
  259.             echo'<td align="center">';
  260.             $Quantity = $row["Quantity"];
  261.                         echo $Quantity. "<br>";
  262.                         echo'</td align="center">';
  263.             echo'<td align="center">';
  264.             $PaidBy = $row["PaidBy"];
  265.                         echo $PaidBy. "<br>";
  266.                         echo'</td align="center">';
  267.             echo'<td align="center">';
  268.             $Cost = $row["Cost"];
  269.                         echo $Cost. "<br>";
  270.                         echo'</td align="center">';
  271.             echo'<td align="center">';
  272.             $SaleDate = $row["SaleDate"];
  273.                         echo $SaleDate. "<br>";
  274.                         echo'</td align="center">';
  275.  
  276.           echo '</tr>';
  277.       }
  278.     echo'</table>';
  279.  
  280.     echo "<br>"; echo "<strong>Sales figures:</strong>"; echo "<hr>";
  281.  
  282.     $sql_total = "SELECT PaidBy, SUM(Cost) FROM cstocksales WHERE MONTH(SaleDate) = '$month' 
  283.                     AND YEAR(SaleDate) = YEAR(CURDATE()) GROUP BY PaidBy";
  284.  
  285.     $result = dbQuery($sql_total);
  286.  
  287.  
  288.  
  289.     while($row = dbFetchArray($result))
  290.           {
  291.          echo "Total sales by ". $row['PaidBy']. "<font color=#CC0000> =  Kshs <strong>". $row['SUM(Cost)']; echo "</font></strong>";
  292.         echo "&nbsp;&nbsp;"; echo"|"; echo "&nbsp;&nbsp;";
  293.         }
  294.  
  295.     $sql_total_final = "SELECT SUM(Cost) FROM cstocksales WHERE MONTH(SaleDate) = '$month' 
  296.                         AND YEAR(SaleDate) = YEAR(CURDATE())";
  297.  
  298.     $result = dbQuery($sql_total_final);
  299.     while($row = dbFetchArray($result))
  300.           {
  301.         echo "<strong>All sales = <font color=#CC0000> Kshs " .$row['SUM(Cost)']; echo "</font></strong>" ;
  302.         }
  303.  
  304.     echo "<br>"; 
  305.     echo '<h4><a href="index.php">Back</a> to sales panel.';
  306.     }
  307. }
  308.  
  309. /* End of month sales*/
  310.  
  311. ?>
  312.  
Please help on how to go about this
Oct 9 '08 #13
pbmods
5,821 Expert 4TB
Wherever you call getPagingLink(), set the third parameter to whatever value you want to set the action to:

Expand|Select|Wrap|Line Numbers
  1. $pagingLink = getPagingLink($sql, $rowsPerPage, 'action=allsalestoday');
  2.  
You'll need to specify a different action each time you call it, but this will add the action parameter to your paging links.
Oct 10 '08 #14
gnawz
64
Thanks for your help.

It added the action to the paging link when I look at the URL but I still get a blank page.

What could be the cause?
Oct 10 '08 #15
pbmods
5,821 Expert 4TB
If you're getting a blank page, your script is probably generating an error. Check out this article to find out what is going on.
Oct 10 '08 #16
gnawz
64
If you're getting a blank page, your script is probably generating an error. Check out this article to find out what is going on.
I have my error capturing all turned on.
Oct 10 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Sharif T. Karim | last post by:
Anyone know of a up-to-date tutorial for pagination where I can have it like: Prev 1 2 3 4 Next Thanks. -- Sharif T. Karim ....you don't know wrath yet...
1
by: Kruq | last post by:
Is it possible to use pagination with DataList? Can't find it.. :( Kruq
2
by: Chris H | last post by:
I am having a problem with pagination, basically the problem is happening in the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue the increment and decrement operators aren't...
4
by: Ed Jay | last post by:
I generate a DHTML page (a medical report) with dynamically generated text based on user input (answers to questions). The page length changes dynamically. I desire that when the page is printed...
2
by: mitra4umohit | last post by:
Hi, I am very new to javascript programming. We are using JSP as UI and Servlet as controller. In our project we have requirement wherein I need to show result in form of list item/link in...
3
Unicron
by: Unicron | last post by:
Hi folks, I have been working on a property listing search for a company for a while now and have hit a roadblock. I have searched the net up and down. A lot of Google results lead to this site, but...
2
by: s4lin | last post by:
problem is pagination not retaining data field i have form with general data field, and i need to select some option which is store in database, so i open another page with retrieving data from...
3
by: raaman rai | last post by:
Please help me with the following code. I have used this pagination script from the net and customized it but unfortunately it doesnt work as expected. The problem is, for the trial purpose i have 3...
4
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.