Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having trouble returning correct record count

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
It appears my php code is returning the amount of records in every table in the db and im not sure why... this is thus throwing off the paging count...


Code:
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Customers = 10;
$pageNum_Customers = 0;
if (isset($_GET['pageNum_Customers'])) {
  $pageNum_Customers = $_GET['pageNum_Customers'];
}
$startRow_Customers = $pageNum_Customers * $maxRows_Customers;

mysql_select_db($database_mysql, $mysql);
$query_Customers = "SELECT * FROM customers ORDER BY clast ";
$query_limit_Customers = sprintf("%s LIMIT %d, %d", $query_Customers, $startRow_Customers, $maxRows_Customers);
$Customers = mysql_query($query_limit_Customers, $mysql) or die(mysql_error());
$row_Customers = mysql_fetch_assoc($Customers);

if (isset($_GET['totalRows_Customers'])) {
  $totalRows_Customers = $_GET['totalRows_Customers'];
} else {
  $all_Customers = mysql_query($query_Customers);
  $totalRows_Customers = mysql_num_rows($all_Customers);
}
$totalPages_Customers = ceil($totalRows_Customers/$maxRows_Customers)-1;

$queryString_Customers = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Customers") == false && 
        stristr($param, "totalRows_Customers") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Customers = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Customers = sprintf("&totalRows_Customers=%d%s", $totalRows_Customers, $queryString_Customers);

?>



paging numbers/next/prev etc..

Code:
 <table border="0" align="center" class="ttable" style="margin-top:5px; margin-bottom:5px;">
    <tr>
	
	<?php if ($pageNum_Customers > 0) { // Show if not first page ?>
      <td>
          <a class="dl" href="<?php printf("%s?pageNum_Customers=%d%s", $currentPage, 0, $queryString_Customers); ?>">First</a>
              </td><?php } // Show if not first page ?>  
     <?php if ($pageNum_Customers > 0) { // Show if not first page ?>
      <td>
          <a class="dl"  href="<?php printf("%s?pageNum_Customers=%d%s", $currentPage, max(0, $pageNum_Customers - 1), $queryString_Customers); ?>">Previous</a>
           </td>   <?php } // Show if not first page ?>  <?php if ($pageNum_Customers < $totalPages_Customers) { // Show if not last page ?>
     
       <?php if($totalPages_Customers > 1) {?>
       <td style="padding-right:3px;">
       <?php

	   for ($pg=1; $pg<$totalPages_Customers+2; $pg+=1) {
		if ($pg>$totalPages_Customers) {break;}
		
			
			if (!($pageNum_Customers==0 && $pg==1)) {
				if (!($pageNum_Customers==$pg)) {
				echo "<a class='dl' title='View page ".$pg."'  href='index.php?pageNum_Customers=".$pg."&totalRows_Customers=".$totalRows_Customers."'>".$pg."</a>&nbsp;";
				
				} else {
				echo "<a class='dl2' title='View page ".$pg."'  href='index.php?pageNum_Customers=".$pg."&totalRows_Customers=".$totalRows_Customers."'>".$pg."</a>&nbsp;";
				
				}
				
			} else {
			
			echo "<a class='dl2' title='View page ".$pg."'  href='index.php?pageNum_Customers=".$pg."&totalRows_Customers=".$totalRows_Customers."'>".$pg."</a>&nbsp;";
			
			}
		
		}

		?>
          </td> <?php } // page numbers ?> 
      <td>
          <a class="dl"  href="<?php printf("%s?pageNum_Customers=%d%s", $currentPage, min($totalPages_Customers, $pageNum_Customers + 1), $queryString_Customers); ?>">Next</a>
          </td> <?php } // Show if not last page ?>     
            
          
      <?php if ($pageNum_Customers < $totalPages_Customers) { // Show if not last page ?><td>
          <a class="dl"  href="<?php printf("%s?pageNum_Customers=%d%s", $currentPage, $totalPages_Customers, $queryString_Customers); ?>">Last</a>
         </td>   <?php } // Show if not last page ?>    
    </tr>
  </table>

Jason

[red]Army[/red] : [white]Combat Engineer[/white] : [blue]21B[/blue]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top