Jump to content

Pagination help


regoch

Recommended Posts

Hi, I got this pagination script and workin fine for me in 3-4 years. But until now i use it in static pages, now i wonna use it on my gallery page that go truogh cms. So problem is here, when i put it in statis page

       	<?php
//Postavke za pagination
//Ime tablice
$tablica="galerije";
//Poredaj po kojem polju i kako
$poredak="id_galerije DESC";
//Ime stranice na kojoj se radi pagination
$targetpage = "/hr/novosti;
//Broj prikaza po stranici
$limit = 1; 
include('pagination.php');	
//Izvršavanje querya kojeg želimo paginationirati
while ($redak=mysql_fetch_array($rezultat))
{ ?>
    <div id="galerije_lista">
    <?php echo 	$redak['naslov_hr']; ?>
    </div>
<?php	}  ?>
    	<?php	
//Ispisivanje pagionationa
echo $paginate;
?>

work fine buit when i get in page that is called by &id_galerije not working.

       	<?php
//Postavke za pagination
//Ime tablice
$tablica="galerije";
//Poredaj po kojem polju i kako
$poredak="id_galerije DESC";
//Ime stranice na kojoj se radi pagination
$galerija_seo=$redak_galerija['galerija_seo_hr'];
$targetpage = "/".$home_jezik."/".$menu_fotogalerija."/".$id_galerije."/".$galerija_seo;
//Broj prikaza po stranici
$limit = 1; 
include('pagination.php');	
//Izvršavanje querya kojeg želimo paginationirati
while ($redak=mysql_fetch_array($rezultat))
{ ?>
    <div id="galerije_lista">
    <?php echo 	$redak['naslov_hr']; ?>
    </div>
<?php	}  ?>
    	<?php	
//Ispisivanje pagionationa
echo $paginate;
?>

htacces code for this page is

RewriteRule ^hr/fotogalerija/(.*)/(.*)$ /galerija.php?id_galerije=$1&galerija_seo=$2

here is live example http://www.sinjske-novine.kus-sinj.hr/hr/fotogalerija/3/22

<?php	
//skripta za pagination
$query = "SELECT COUNT(*) as num FROM $tablica";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];

$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
	$start = ($page - 1) * $limit; 
}else{
	$start = 0;	
	}	

    //Dohvati podatke iz baze
$query1 = "SELECT * FROM $tablica ORDER BY $poredak LIMIT $start, $limit";
$rezultat = mysql_query($query1);

if ($page == 0){$page = 1;}
$prev = $page - 1;	
$next = $page + 1;							
$lastpage = ceil($total_pages/$limit);		
$LastPagem1 = $lastpage - 1;					


$paginate = '';
if($lastpage > 1)
{	




	$paginate .= "<div class='paginate'>";
	// Predhodna
	if ($page > 1){
		$paginate.= "<a href='$targetpage?page=$prev'> << </a>";
	}else{
		$paginate.= "<span class='disabled'> << </span>";	}



	//Stranice
	if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
	{	
		for ($counter = 1; $counter <= $lastpage; $counter++)
		{
			if ($counter == $page){
				$paginate.= "<span class='current'>$counter</span>";
			}else{
				$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
		}
	}
	elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
	{
		if($page < 1 + ($stages * 2))		
		{
			for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
			}
			$paginate.= "...";
			$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
			$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
		}
		elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
		{
			$paginate.= "<a href='$targetpage?page=1'>1</a>";
			$paginate.= "<a href='$targetpage?page=2'>2</a>";
			$paginate.= "...";
			for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
			}
			$paginate.= "...";
			$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
			$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
		}
		else
		{
			$paginate.= "<a href='$targetpage?page=1'>1</a>";
			$paginate.= "<a href='$targetpage?page=2'>2</a>";
			$paginate.= "...";
			for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
			}
		}
	}

			//Sljedeća
	if ($page < $counter - 1){ 
		$paginate.= "<a href='$targetpage?page=$next'> >> </a>";
	}else{
		$paginate.= "<span class='disabled'> >> </span>";
		}

	$paginate.= "</div>";		


}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.