how to paginate my site pages?

Discussion in 'PHP' started by es-es, Jun 24, 2012.

  1. #1
    Hello i'have a website,assume that there are some pages in root directory such as index.php, page1.php, page2.php... and so on.The problem is i dont know how to import these files into my pagination table here is my pagination table:
    
    <?php
    mysql_select_db('haberler' ,mysql_connect('localhost','root','')) or die(mysql_error());
    $page= (!isset($_REQUEST['page']) || !ctype_digit($_REQUEST['page'])) ? 0 : $_REQUEST['page']; 
    if(!$page) $page = 1;
    $total = mysql_num_rows(mysql_query("select * from haberler"));
    $limit = 5;
    $show = $page * $limit - $limit;
    
    $query = mysql_query("select * from haberler limit $show,$limit");
      
         while($row = mysql_fetch_array($query)) {
         
            
            echo '<span class="haber">'.$row['haberler'].'</span>';
    
         }
    $page_last = ceil($total/$limit);
    $forlimit = 3;
    
      echo '<div class="sayfala">';
    
      if($page > 1){
        $previous = $page -1;
        echo '<a class="sayfa" href="index.php">First</a><a class="sayfa" href="index.php?page='.$Previous.'">Previous</a>';
      }
      for($i = $page - $forlimit; $i < $page + $forlimit +1; $i++){
        
        if($i > 0 && $i <= $page_last){
            
            if($i == $page){
                
                echo '<span class="aktif">'.$i.'</span>';
            }else{
                echo '<a class="page" href="index.php?page='.$i.'">'.$i.'</a>';
            }
        }
      }
      
      if($page != $page_last){
        
        echo '<a class="page" href="index.php?sayfa='.($page +1).'">Next</a>';
        echo '<a class="page" href="index.php?page='.$page_last.'">Last</a>';
        
      }
      echo '</div>';
    ?>
    
    PHP:
    i just want to learn how to import my specific php pages into a table row

    table name= katalog with 5 rows
    row 1 value= product 1, row 2 value= product 2, and so on. i'm paginating these values but i want to use a php page instead of these values
    please help how can i do that?
     
    Last edited: Jun 24, 2012
    es-es, Jun 24, 2012 IP
  2. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #2
    Do you understand what your code does?
    Do you understand what it is to PAGINATE?

    First...your code executes an SQL statements then displays 5 results depending on what $page is set to. Your code then generates HTML links to navigate through the result set. It's specific to the current script and SQL query. It has absolutely nothing to do with linking to static files in a directory.

    Second...if you want to link to static files odds are you do NOT need some sort of paginate code to do so. Just write out your HTML links manually. IF you have hundreds of files in a directory...or even just dozens you *could* 1. read the dir to get a directory listing then 2. create a similar chunk of code to paginate the results however I would HIGHLY recommend you to come up with a better approach.
     
    NetStar, Jun 24, 2012 IP
  3. atxsurf

    atxsurf Peon

    Messages:
    2,394
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    0
    #3
    your "select * from haberler limit $show,$limit" is the pagination statement where $limit is the page size and $show=($page-1)*$limit
     
    atxsurf, Jun 24, 2012 IP
  4. es-es

    es-es Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    mypaginate.jpg
    1-this ↑ my pagination screenshot,i want to insert into rows apage.php for example, instead of the value haber 2, haber 3 ...
    phppagination.jpg
    2-and this ↑ is phpmyadmin table screenshot, how can i insert a specific php pages into these values, and paginate with below codes
    3-
    <?phpmysql_select_db('haberler' ,mysql_connect('localhost','root','')) or die(mysql_error());$page= (!isset($_REQUEST['page']) || !ctype_digit($_REQUEST['page'])) ? 0 : $_REQUEST['page']; if(!$page) $page = 1;$total = mysql_num_rows(mysql_query("select * from haberler"));$limit = 5;$show = $page * $limit - $limit;
    $query = mysql_query("select * from haberler limit $show,$limit");       while($row = mysql_fetch_array($query)) {                     echo '<span class="haber">'.$row['haberler'].'</span>';
         }$page_last = ceil($total/$limit);$forlimit = 3;
      echo '<div class="sayfala">';
      if($page > 1){    $previous = $page -1;    echo '<a class="sayfa" href="index.php">First</a><a class="sayfa" href="index.php?page='.$Previous.'">Previous</a>';  }  for($i = $page - $forlimit; $i < $page + $forlimit +1; $i++){        if($i > 0 && $i <= $page_last){                if($i == $page){                        echo '<span class="aktif">'.$i.'</span>';        }else{            echo '<a class="sayfa" href="index.php?page='.$i.'">'.$i.'</a>';        }    }  }    if($page != $page_last){        echo '<a class="page" href="index.php?page='.($page +1).'">Next</a>';    echo '<a class="page" href="index.php?page='.$page_last.'">Last</a>';      }  echo '</div>';?>
    PHP:
    can you provide or write me a sample code to paginate with that code ↑? or can you direct me how can do it on my own?
    thank you very much
     
    es-es, Jun 24, 2012 IP