Jump to content
php.lv forumi

Lapu dalīšana.


savejais

Recommended Posts

man ir laikam kaukas kotev vajag, negribās pielāgot tev kodu, pamēģini izlobīt ārā pac, mok sanāk:

 

if(!isset($_GET['page'])){
  $page = 1;
} else {
  $page = $_GET['page'];
}

$max_results = 15;
$from = (($page * $max_results) - $max_results);

$sql = "SELECT * FROM table_name order by id desc LIMIT $from, $max_results";

$total_results = mysql_result(mysql_query("SELECT COUNT(id) as Num FROM tablename"),0);
$total_pages = ceil($total_results / $max_results);
echo "<center><br />";

// Ieprieksheejaa lapa
if($page > 1){
  $prev = ($page - 1);
  echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\" style='font-size: 7pt;'>Sākums</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
  if(($page) == $i){
   echo "<FONT SIZE=\"1\" face=\"tahoma\">Lapa $i </FONT>"; //Lapas nummurs
   } else {
	   echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\" style='font-size: 7pt;'>$i</a> ";
  }
}
// Naakoshaa lapa
if($page < $total_pages){
  $next = ($page + 1);
  echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\" style='font-size: 7pt;'>Pēdējie</a>";
}
echo "<BR><FONT SIZE=\"1\" face=\"tahoma\">Kopā posti $total_results</FONT><BR>";
echo "</center>";

 

Nu man vismaz tā ir, ikā strādā ;)

Link to comment
Share on other sites

×
×
  • Create New...