Jump to content

[Resolvido] Paginação


PF2G

Recommended Posts

Boas,

eu estou a fazer uma galeria de imagens onde tenho um sistema de paginação.

Neste momento tenho a listagem das imagens, mas não me divide pelas diferentes páginas...

<?php
if($page == "all"){
$page_number = 1;
// how many records per page
$size = 8;

// we get the current page from $_GET
if (isset($_GET['page'])){
 $page_number = (int) $_GET['page'];
}
/**************************************************/
$result_images=mysql_query("SELECT * FROM  album_lang WHERE lang='".$current_lang."'");
$row_images=mysql_fetch_assoc($result_images);

$result_content=mysql_query("SELECT * FROM album_images_lang WHERE lang='".$current_lang."' AND visivel=1 ");
$total_records = mysql_num_rows($result_content);

$result_imagens=mysql_query("SELECT * FROM album_images WHERE id='".$total_records['id_image']."' AND visivel=1");
$total_imagens=mysql_fetch_assoc($result_imagens);
/**************************************************/

// create the pagination class
$pagination = new Pagination();
$pagination->setLink($current_lang."/gallery/all?page=%s");
$pagination->setPage($page_number);
$pagination->setSize($size);
$pagination->setTotalRecords($total_records);
/**************************************************/
$result_content=mysql_query("SELECT * FROM album_lang WHERE titulo='' AND lang='$current_lang' AND visivel=1 " . $pagination->getLimitSql());
/**************************************************/

$navigation = $pagination->create_links();
}else{
/**************************************************/
if(isset($clean_url[3]) && $clean_url != ""){
 $product = $clean_url[3];
 $result_content=mysql_query("SELECT * FROM album_lang WHERE titulo='".$clean_url[2]."' AND lang='$current_lang' AND visivel=1");
}else{
/**************************************************/
 $page_number = 1;

 // how many records per page
 $size = 8;

 // we get the current page from $_GET
 if (isset($_GET['page'])){
  $page_number = (int) $_GET['page'];
 }


/**************************************************/ 
 $result_content=mysql_query("SELECT * FROM album_images WHERE visivel=1");
 $total_records = mysql_num_rows($result_content);
/**************************************************/
 // create the pagination class
 $pagination = new Pagination();
 $pagination->setLink($current_lang."/gallery/all?page=%s");
 $pagination->setPage($page_number);
 $pagination->setSize($size);
 $pagination->setTotalRecords($total_records);
/**************************************************/ 
 $result_content=mysql_query("SELECT * FROM album WHERE id='".$tax_id."' AND lang='$current_lang' AND visivel=1 " . $pagination->getLimitSql());
/**************************************************/
 $navigation = $pagination->create_links();

}
}

$num_rows_content = mysql_num_rows($result_content);
$conta_rows_content = 1;
$content = "";
if($num_rows_content > 0 || $page == "all"){
echo '<div class="content" id="page">
 <div class="container">
  <div class="interior_page" style="border-bottom:0px;">';
   if($page == "all"){
    $pageTitle="GALERIA";
   }else{
    if(isset($clean_url[3]) && $clean_url != ""){
	 $pageTitle = $row_content->titulo;
    }else{
	 $result_tax_titulo = mysql_query("SELECT * FROM `album_images` WHERE visivel=1 LIMIT 0,1");
	 $row_tax_titulo = mysql_fetch_object($result_tax_titulo);
	 $row_titulo=mysql_fetch_assoc($result_tax_titulo);

	 $pageTitle = $row_tax_titulo->title;
    }
   }

   echo '<div id="menu_produtos">';

   echo '</div>';

   if($num_rows_content > 1 || !isset($clean_url[3])){

    //Se existir mais que um produto apresenta a listagem de todos os existentes

    echo '<div id="products">';
	 echo "<h1 class='title'>".$pageTitle."</h1>";

	 echo '<div class="produts_list">';
	 $count_products = 1;

   //////////   IMAGENS TODAS   ////////////
	 /***************************/
	  $sel_imagem="SELECT * FROM album_images";
	  $imagem=mysql_query($sel_imagem, $con);

	 ?>
	  <table width="100%">
	 <?php
	  $i=0;
	   while ($linha = mysql_fetch_array($imagem))
	   {
	    if ($i==0)
	    {
		 echo '<tr>';
	    }

	    echo '<td>';
	    echo '<table><tr><td><a href="#"><img src="'.$linha['imagem'].'" width="150px" height="150px"></a></td></tr>';
	    echo '<tr><td align="center"></td></tr></table>';
	    echo '</td>';
	    $i=$i+1;
	    if ($i==4)
	    {
		 $i=0;
	    }
	   }
	 ?>
	  </table>
	 <?php
    /////////   IMAGENS P/ CATEG   /////////


	 /***************************/

	 /* Paginação */
	 echo '<div class="clearfloat"></div>';
	 echo $navigation; // will draw our page navigation
	 echo '<div class="clearfloat"></div>';
	 echo '</div>';

    echo '</div>';

   }

   echo '<div class="clearfloat"></div>';
  echo  '</div>
   <div class="clearfloat"></div>';
echo  '</div>
 </div>';

}else{
header("Status: 404 Not Found");
header( "Location: ".$url."/".$current_lang."/pages/error/404" );
die();
}
?>
Link to comment
Share on other sites

Já pesquisei varios exemplos e são todos de qualquer coisa como isto:

//////////   IMAGENS TODAS   ////////////
	 /***************************/
	 if($clean_url[2]='all'){
	  $sel_imagem="SELECT * FROM album_images ORDER BY id'". $pagination -> setSize;
	  $imagem=mysql_query($sel_imagem, $con);

	 ?>
	  <table width="100%">
	 <?php
	  $i=0;
	   while ($linha = mysql_fetch_assoc($imagem))
	   {
		if ($i==0)
		{
		 echo '<tr>';
		}

		echo '<td>';
		echo '<table><tr><td><img src="'.$linha['imagem'].'" width="150px" height="150px"></td></tr>';
		echo '<tr><td align="center"></td></tr></table>';
		echo '</td>';
		$i=$i+1;
		if ($i==4)
		{
		 $i=0;
		}
	   }

	 ?>
	  </table>
	 <?php
	 ;}

mas dá-me erro:

Notice: Undefined property: Pagination::$setSize in C:\wamp\www\www.iberveda.com\pages\gallery.php on line 117

Alguem me pode ajudar?

Obrigado,

PF2G

Edited by PF2G
Link to comment
Share on other sites

Era a query que estava a seleccionar as imagens. Aqui fica o pedaço de codigo correto:

//Monta o SQL com LIMIT para exibição dos dados 
	  $sql = "SELECT * FROM album_images ORDER BY id ASC " . $pagination->getLimitSql();
	  $images  = mysql_query($sql) or die(mysql_error());

    ?>

    <table>
	 <?php
	   $i=0;
	   while($ln = mysql_fetch_assoc($images)){
	  if ($i==0)
	  {
	   echo '<tr>';
	  }
	 ?>

	  <td>
	  <table><tr><td><a href=""><img src="<?php echo $ln['imagem']; ?>" width="150px" height="150px"></a></td></tr>
	  <tr><td align="center"></td></tr></table>
	  </td>
	 <?php
	  $i=$i+1;
	  if ($i==4)
	  {
	   $i=0;
	  }
	   }
	 ?>
    </table>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.