Pls modify this code with pagination

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Pls modify this code with pagination

    Pls modify this below code with pagination

    PHP Code:
    <?php
    $host
    ="localhost"// Host name
    $username="Black_froum"// Mysql username
    $password="root"// Mysql password
    $db_name="Black_froum"// Database name
    $tbl_name="forum_question"// Table name

    // Connect to server and select databse.
    mysql_connect("$host""$username""$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    $sql="SELECT * FROM $tbl_name ORDER BY id DESC";
    // OREDER BY id DESC is order result by descending

    $result=mysql_query($sql);
    ?>

    <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
    <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
    <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
    <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
    <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
    </tr>

    <?php
    // Start looping table row
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
    <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
    <td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>
    <td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>
    <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>
    </tr>
    <?php
    // Exit looping and close connection
    }
    mysql_close();
    ?>

    <tr>
    </tr>
    </table>
    example like this <Prev 1.2.3.4..>next Viewall
    Last edited by arnage; 18.06.13, 11:46.

    #2
    Originally posted by Jeevi Tha View Post
    Pls modify this below code with pagination

    PHP Code:
    <?php
    $host
    ="localhost"// Host name
    $username="Black_froum"// Mysql username
    $password="root"// Mysql password
    $db_name="Black_froum"// Database name
    $tbl_name="forum_question"// Table name

    // Connect to server and select databse.
    mysql_connect("$host""$username""$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    $sql="SELECT * FROM $tbl_name ORDER BY id DESC";
    // OREDER BY id DESC is order result by descending

    $result=mysql_query($sql);
    ?>

    <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
    <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
    <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
    <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
    <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
    </tr>

    <?php
    // Start looping table row
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
    <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
    <td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td>
    <td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td>
    <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td>
    </tr>
    <?php
    // Exit looping and close connection
    }
    mysql_close();
    ?>

    <tr>
    </tr>
    </table>
    example like this <Prev 1.2.3.4..>next Viewall
    follow this link PHP / MySQL select data and split on pages | PHP Tutorial by PHP Jabbers

    try to do it yourself by trial and error. if you fail then post your code and someone will take a look at it.
    sigpic

    Comment


      #3
      Yup.,

      $page=$_REQUEST['page'];
      if($page=="" OR $page==0 OR $page=1)
      {
      $page=1;
      $start=$page*10-10;
      }
      $cmd="select * from table limit $start,10";

      //fetch this cmd and it will show you the first 10 result

      and next link

      <a href="<? echo $_SERVER['PHP_SELF']; ?>?page=<? echo $page+1; ?>"> Next </a>

      Comment

      Working...
      X