Mysql
 sql >> Database >  >> RDS >> Mysql

A richiesta impaginazione(Paginate record su richiesta dell'utente)

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>";