Jump to content

Issue with Pagination Formatting


HDFilmMaker2112

Recommended Posts

If you go to this page:

http://www.ghosthuntersportal.com/store.php?cat=emf-meters

 

You can see that the page is misformatted, but if you click the link to page 2 or the Next Link, that page is perfectly fine. Ideas on why the first page is misformatted? They're both coming from the same PHP script, and the CSS defined in those div tag and span tags doesn't exist yet.

 

Link to comment
https://forums.phpfreaks.com/topic/238407-issue-with-pagination-formatting/
Share on other sites

Here's the PHP:

 

if(isset($_GET['cat'])){
$cat=$_GET['cat'];
$cat=str_replace("-"," ", $cat);

if(isset($_POST['num_products'])){
$num_product_per_page=$_POST['num_products'];
$num_product_per_page = stripslashes($num_product_per_page);
$num_product_per_page = mysql_real_escape_string($num_product_per_page);
}
else{
$num_products_per_page="4";
}
$num_products='';

if(isset($_POST['sort_by'])){
$sort_by_selected=$_POST['sort_by'];
$sort_by_selected = stripslashes($sort_by_selected);
$sort_by_selected = mysql_real_escape_string($sort_by_selected);
}
else{
$sort_by_selected="product_id";
}
$sort_by='';

// How many adjacent pages should be shown on each side?
$adjacents = 3;

/* 
First get total number of rows in data table. 
If you have a WHERE clause in your query, make sure you mirror it here.
*/

$query5 = "SELECT COUNT(*) as num FROM $tbl_name WHERE product_category='$cat'";
$total_pages = mysql_fetch_array(mysql_query($query5));
$total_pages = $total_pages[num];

/* Setup vars for query. */
$targetpage = "store.php?cat=".$_GET['cat']; 	//your file name  (the name of this file)
$limit = $num_products_per_page;		//how many items to show per page
$page = $_GET['page'];

if($page){
$start = ($page - 1) * $limit; 			//first item to display on this page
}
else{
$start = 0;								//if no page var is given, set start to 0
}

	/* Get data. */
	$sql30 = "SELECT * FROM $tbl_name WHERE product_category='$cat' ORDER BY $sort_by_selected LIMIT $start, 		$limit";
	$result30 = mysql_query($sql30) or die("Problem with the query: $sql30<br>" . mysql_error());

/* Setup page vars for display. */
if ($page == 0){ $page = 1; }				//if no page var is given, default to 1.
$prev = $page - 1;							//previous page is page - 1
$next = $page + 1;							//next page is page + 1
$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1;						//last page minus 1

/*Now we apply our rules and draw the pagination object. 
We're actually saving the code to a variable in case we want to draw it more than once.
*/

$pagination = "";
if($lastpage > 1){
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1){
$pagination.= '<a href="'.$targetpage.'&page='.$prev.'">&#171; Previous</a>';
}
else{
$pagination.= "";
}

	//pages	
	if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
	{
		for ($counter = 1; $counter <= $lastpage; $counter++)
		{
			if ($counter == $page){
			$pagination.= "<span class=\"current\">$counter</span>";
			}
			else{
			$pagination.= '<a href="'.$targetpage.'&page='.$counter.'">'.$counter.'</a>';					
			}
		}
	}
	elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
	{
		//close to beginning; only hide later pages
		if($page < 1 + ($adjacents * 2)){
			for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){
				if ($counter == $page){
				$pagination.= "<span class=\"current\">$counter</span>";
				}
				else{
				$pagination.= '<a href="'.$targetpage.'&page='.$counter.'">'.$counter.'</a>';		
				}
			}
		$pagination.= "...";
		$pagination.= '<a href="'.$targetpage.'&page='.$lpm1.'">'.$lpm1.'</a>';
		$pagination.= '<a href="'.$targetpage.'&page='.$lastpage.'">'.$lastpage.'</a>';		
		}

	//in middle; hide some front and some back
	elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)){
	$pagination.= '<a href="'.$targetpage.'&page=1">1</a>';
	$pagination.= '<a href="'.$targetpage.'&page=2">2</a>';
	$pagination.= "...";
		for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++){
			if ($counter == $page){
			$pagination.= "<span class=\"current\">$counter</span>";
			}
			else{
			$pagination.= '<a href="'.$targetpage.'&page='.$counter.'">'.$counter.'</a>';			
			}
		}
		$pagination.= "...";
		$pagination.= '<a href="'.$targetpage.'&page='.$lpm1.'">'.$lpm1.'</a>';
		$pagination.= '<a href="'.$targetpage.'&page='.$lastpage.'">'.$lastpage.'</a>';		
	}

//close to end; only hide early pages
	else
	{
	$pagination.= '<a href="'.$targetpage.'&page=1">1</a>';
	$pagination.= '<a href="'.$targetpage.'&page=2">2</a>';
	$pagination.= "...";
		for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
		{
			if ($counter == $page){
			$pagination.= '<span class="current">'.$counter.'</span>';
			}
			else{
			$pagination.= '<a href="'.$targetpage.'&page='.$counter.'">'.$counter.'</a>';							}
		}
	}
        }
}

//next button
if ($page < $counter - 1){
$pagination.= '<a href="'.$targetpage.'&page='.$next.'">Next &#187;</a>';
}
else{
$pagination.= "";
$pagination.= "</div>\n";		
}
}

$cat2=str_replace(" ","-", $cat);
while($row30=mysql_fetch_array($result30)){
extract($row30);
$section=ucwords($product_category);
$crumbs='<a href="./index.php">Home</a> <span class="eleven">&#187;</span> <a href="./store.php?cat='.$cat2.'">'.$section.'</a>';
$section=" - ".$section;
$product_name=ucwords($product_name);
$content.='<div class="content_text2"><div class="product"><div><a href="./store.php?product='.$product_id.'"><img src="/images/'.$product_image.'" alt="'.$product_name.'" class="product_image" /></a></div>
<div><a href="./store.php?product='.$product_id.'">'.$product_name.'</a></div>
<div>Price: $'.number_format($product_price, 2, '.', ',').'</div>
<div>'.$product_link.'</div></div></div>';
}
$records_on_page = mysql_num_rows($result30);
$start_record = $start + 1;
$end_record = $start_record + $records_on_page -1;
$products_on_page="Showing ".$start_record." - ".$end_record." out of ".$total_pages." product";
if($total_pages > 1){
$products_on_page.="s";
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head>
<base href="http://ghosthuntersportal.com/" />
<title>Ghost Hunter's Portal <?php echo "$section"; ?></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="verify-v1" content="" />
<meta name="keywords" content="ghost, hunters, hunter, ghosts, spirit, spirits, paranormal, investigation, investigator, investigators, k2, emf, meter, kii" />
<meta name="description" content="Ghost Hunters Potal. Parnormal research equipment store." />
<meta name="author" content="Andrew McCarrick" />
<meta name="robots" content="index, follow" />

<?php
if($_GET['donate']=="thankyou"){
echo '<meta http-equiv="refresh" content="5;url=http://makethemoviehappen.com/index.php">';
}
elseif($_GET['donate']=="cancel"){
echo '<meta http-equiv="refresh" content="1;url=http://makethemoviehappen.com/index.php">';
}
else{
}
?>
<style type="text/css">
<?php
if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE 7")) {
echo 'body {background-color: #000000; color: #FFFFFF; font-family: Tahoma; margin-top: 10px;
margin-right:auto;margin-left:auto;max-width:1000px;}';
} else {
echo 'body {background-color: #000000; color: #FFFFFF; font-family: Verdana; margin-top: 10px;
margin-right:auto;margin-left:auto;max-width:1000px;}'; 
}
?>
</style>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="shortcut icon" href="./favicon.png" />
<? 
if(isset($_GET['product'])){
include 'ajax.php'; 
}
?>
</head>
<body <? if(isset($_GET['product'])){ echo 'onload="load();"';} ?>>
<div class="header">
<a href="./index.php">
<div class="logo"><img src="./logo.png" alt="Ghost Hunter's Portal" /></div>
<div class="tag"><img src="./tag.png" alt="Ghost Hunter's Portal" /></div>
</a>
<div class="header_right">
<div class="ad">

</div>
<div class="header_links">
<a href="./index.php">Home</a> | <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_cart&business=A2YAZNFRRYNFG&display=1">View Cart</a> | <a href="./index.php?returns">Returns</a> | <a href="./index.php?aboutus">About Us</a> | <a href="./index.php?contactus">Contact Us</a>
</div>
</div>
</div>
<div class="content_wrapper">
<div class="links">
<div class="categories">Categories</div>
<?php
$sql100="SELECT DISTINCT product_category FROM $tbl_name";
$result100=mysql_query($sql100);
while($row100=mysql_fetch_array($result100)){
$product_category=$row100['product_category'];
$product_category_link=$product_category;
$product_category_link=strtolower($product_category_link);
$product_category_link=str_replace(" ","-", $product_category_link);
$product_category=ucwords($product_category);
echo '<div><a href="store.php?cat='.$product_category_link.'">'.$product_category.'</a></div>'."\n";
}
?>
<div class="sig"><img src="./sig.png" /></div>
</div>
<div class="data_wrapper">
<div class="search_crumbs">
<div class="crumbs">
<? echo $crumbs; ?>
</div>
<div class="search">
<form action="./index.php?search" method="post">
<label>Search</label> <input type="text" name="search" size="30" />
<input type="submit" value="Go" name="Go" />
</form>
</div>
</div>
<?
if(isset($products_on_page)){
echo "
<div class=\"number_pages_wrapper\">
<div class=\"number_products\">$products_on_page</div>
<div class=\"page_numbers\">$pagination</div>
</div>
<div class=\"number_pages_wrapper\">
<div class=\"number_products\">$sort_by</div>
<div class=\"page_numbers\">$num_products</div>
</div>
";
}
?>
<div class="content">
<? echo $content; ?>
</div>
<?
echo "
<div class=\"number_pages_wrapper\">
<div class=\"number_products\"> </div>
<div class=\"page_numbers\">$pagination</div>
</div>"
?>
<br />
</div>
</div>
<div class="footer">
© 2011 <?php echo $copyrightdate; ?> Ghost Hunter's Portal, L.L.C.
</div>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.