Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Atas permintaan pagination (Catatan paginasi sesuai permintaan pengguna)

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

if(isset($_GET['dark']))
{
    $max_result=$_GET['dark'];

}
else
{
    $max_result=5;
}

$from=(($page*$max_result)-$max_result);

mysql_select_db("db",$con);
$sql = "SELECT COUNT(*) FROM `db`.`table` ";
$result=mysql_query($sql);

$total_result=mysql_result($result,0);
$total_pages=ceil($total_result/$max_result);

if($total_result>$max_result)
{
    if($page>1)
    {
        $prev=$page-1;
        echo "<a href=\"".$_SERVER['PHP_SELF']."?dark=".$max_result."&page=$prev\">previous</a>";
    }
    for($i=1;$i<=$total_pages;$i++)
    {
        if($page==$i)
        {
        echo "<strong>".$i."</strong>";
        }
        else
        {
        echo "<a href=\"".$_SERVER['PHP_SELF']."?dark=".$max_result."&page=$i\">$i</a> ";
        }
        if($page<$total_pages)
        {
        $next=$page+1;

        //echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";
        }
    }

        if($page<$total_pages)
        {
                $next=$page+1;
                echo "<a href=\"".$_SERVER['PHP_SELF']."?dark=".$max_result."&page=$next\">next</a>";
        }
}

         echo "<table><tr>";

            echo "<td><form action='helloworld.php' name='get'>
                <select name='dark'>
                <option value='2'>2</option>
                <option value='5'>5</option>
                <option value='10'>10</option>
                </select>
                <input type='hidden' name='searching' value='yes' /><input type='submit' value='No.of entries'>
                </form></td></tr>";         
            echo "<tr><td><strong>PAGE NUMBER $page of $total_pages.</strong>.</td></tr>";
            echo"</table>";


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Konfigurasi indeks MySQL

  2. Tips Upgrade Percona XtraDB Cluster ke 8.0

  3. MySQL memberikan 'user.id' kolom Tidak Dikenal dalam kesalahan 'daftar bidang' menggunakan id otomatis Django

  4. MySQL:Memilih beberapa bidang menjadi beberapa variabel dalam prosedur tersimpan

  5. MySQL:Kepemilikan direktori mysql berubah menjadi 'mysql' dari 'service_account' di server linux reboot