473,756 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on pagination please

64 New Member
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 2777
code green
1,726 Recognized Expert Top Contributor
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 New Member
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 Recognized Expert Top Contributor
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 Recognized Expert Expert
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 New Member
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 Recognized Expert Expert
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 Recognized Expert Top Contributor
Merged with duplicate thread (thread843785.h tml). Thanks
Oct 7 '08 #8
code green
1,726 Recognized Expert Top Contributor
This is an awful lot of code, and that is in both sense of the word awful.Neverthel ess 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 Recognized Expert Expert
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

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

Similar topics

9
3407
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
5816
by: Kruq | last post by:
Is it possible to use pagination with DataList? Can't find it.. :( Kruq
2
2327
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 functioning or the $page variable isnt working in that part of the code... Below is the link to the working but broken page.. as well as the main part of my code... Hopefully someone can explain why the operators arent working or maybe see what i...
4
3647
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 and reaches a specific length, it terminates printing that page, prints a page number, and then begins to print the next page using the same header and format as the previous page. The page uses no tables or paragraph elements, only CSS. IOW, I...
2
1968
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 rows and if result has more than 5 rows there should be one more link on click of which it should go to page where we can have pagination for those results. Now this listing should be collapsible, means if user wishes he can collapse or expand...
3
6403
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 I have never been able to get it to work. Here's the setup- The user submits search criteria via POST. The results php page pulls the $_POST array and displays the results with pagination of 20 results per page with links for Next/Previous. ...
2
1858
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 table with pagination form data's are retaining if i select from first page but data not retaining if i select option from other than 1st page. i m using hidden field in pagination page. Thanks stalin
3
1586
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 records in the table and i have set the limit value to 2 only for now (for trial). So it is expected that i have 2 records displayed in the first page and 1 record in the second page. The first two records are displayed normally with the NEXT link....
4
3575
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, and the pagination almost works. The first page of the pagination works fine, but when I click on one of the links for one of the next pages, the page is blank. I have seen people mention this problem, and they have been told that a variable is...
0
10031
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9708
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.