views:

117

answers:

5

hello i want to list contents as 10 contents per page

this is source code for each content

<?
while ($arama=mysql_fetch_array($arama_sonuc)) {    
?>
<h4><a href="oku.php?id=<?=$arama[id]?>"><?=$arama[baslik]?></a></h4>
                    <div class="article box">
                        <div class="article-desc-oku">

                            <p class="info">Yayınlanma: <strong><?=$arama[eklemetarihi]?></strong><br />
                            Yazan:  <strong><a href="#">Ronnie C. Lynwood</a></strong><br /><?=$arama[tiklanma]?> kez okunmuş.<br />
                            <?php rating_form("$arama[id]"); ?>
                            </p>

                        </div>
                  <?=$arama[spot]?>
                    </div> <!-- /article -->
+4  A: 

I think you should better use a paging class rather than creating your own. This will save a lot of time of yours in next projects too. Your current problem will also be solved. Check this out.

Download Location

Sarfraz
I have my own class that does this, which I share across all my PHP projects - so +1 for this answer.
Sohnee
@Sarfraz Ahmed:No Download Link.@Sohnee:wanna share it with us?
amindzx
@amindzx: please check this, it is here: http://php-paging-class.googlecode.com/svn/trunk/
Sarfraz
@@Sarfraz Ahmed: thanks!
amindzx
+1  A: 

Here http://php.about.com/od/phpwithmysql/ss/php_pagination.htm you can find a complete code example on pagination. It's also explained very well.

Sorry but I can't offer more just by seeing a snipped of code ...

Tim
+2  A: 

It looks like you are using MySQL: You can build a query using the SQL LIMIT command.

For example:

SELECT * FROM myTable LIMIT 5, 10

Will tell MySQL to return only the first ten elements after the 5th row. You can use a parameter on the query string to build an appropriate SQL query to "ask" the database which "page" you want to see.

Lorenzo V.
A: 

i used codes below to make pagination

<?
if (isset($_GET['sayfa'])) {
   $pageno = $_GET['sayfa'];
} else {
   $pageno = 1;
} // if
$query = mysql_query("SELECT count(id) FROM yazilar");
$query_data = mysql_fetch_row($query);
$numrows = $query_data[0];
$rows_per_page = 10;
$lastpage      = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
   $pageno = $lastpage;
} // if
if ($pageno < 1) {
   $pageno = 1;
} // if
$limit = 'ORDER BY id DESC LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = mysql_query("SELECT * FROM yazilar $limit");
if ($pageno == 1) {
   echo " İLK ÖNCEKİ ";
} else {
   echo " <a href='{$_SERVER['PHP_SELF']}?sayfa=1'>İLK</a> ";
   $prevpage = $pageno-1;
   echo " <a href='{$_SERVER['PHP_SELF']}?sayfa=$prevpage'>ÖNCEKİ</a> ";
} // if
echo " ( Sayfa $pageno ) ";
if ($pageno == $lastpage) {
   echo " SONRAKİ SON ";
} else {
   $nextpage = $pageno+1;
   echo " <a href='{$_SERVER['PHP_SELF']}?sayfa=$nextpage'>İLERİ</a> ";
   echo " <a href='{$_SERVER['PHP_SELF']}?sayfa=$lastpage'>SON</a> ";
} // if
?>
Ronnie Chester Lynwood
A: 

Let me suggest some existing PHP solutions

Zend_Paginator, loosely coupled can be used stand alone without the whole framework.

If you want to build your own flavour I recommand the SPL countable and Iterator classes.

Elzo Valugi
Can you add a little more on the SPL part? Maybe some example code on how to use the SPL on paging. Thanks
AntonioCS
countable is an interface not a class
AntonioCS
The basic idea would be to fill an Iterator with whatever you want and then use a LimitIterator to only iterate over the 'page' that you want. E.g. `$it = new DirectoryIterator('.'); $page = new LimitIterator($it, $offset, $perpage); foreach ($page as $row) { /*...*/ }`(P.S. I don't know if the code above will render properly, still getting used to SO.)
salathe