Jump to content
php.lv forumi

Pagination fix


sidrs

Recommended Posts

Sadalu db ierakstus pa lapām, katrā lapā 4 ieraksti.

Vaidzētu panakt, lai ieraksti numurējas pēc kārtas. pirma lapa 1, 2, 3 ,4 ieraksts. otra lapa 5, 6, 7, 8 ieraksts.

Pagaidām rāda katrā lapā 1, 2, 3, 4

Varbūt kādam ir kāda ideja?

 

kods

$data = mysql_query("SELECT * FROM tabula") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 4;
$last = ceil($rows/$page_rows);
if($pagenum < 1) 
   { 
    $pagenum = 1; 
   } 
elseif($pagenum > $last) 
   { 
    $pagenum = $last; 
   }
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; 
$data_p = mysql_query("SELECT * FROM tabula order by skaits desc $max") or die(mysql_error()); 
while($info = mysql_fetch_array( $data_p ))
   {
 $n+=1;
    echo '
    '.$n.' '.$info['name'].'
 <br />
 ';
}

Link to comment
Share on other sites

$n=$pagenum*$page_$rows-$page_$rows;
while($info = mysql_fetch_array( $data_p ))
{
 $n+=1;
 echo '
   '.$n.' '.$info['name'].'
       <br />
    ';
}

 

un so:

$data = mysql_query("SELECT * FROM tabula") or die(mysql_error());
$rows = mysql_num_rows($data);

labak aizvietot ar:

$data = mysql_query("SELECT count(*) FROM tabula") or die(mysql_error());
$row = mysql_fetch_row($data);
$rows=$row[0];

kompitim daudz vieglak bus paveikt tadu pieprasijumu

Edited by Blitz
Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...