Hello,
every google user must have seen how they show the Result pages like " Previous 1 2 3 4 Next ".Could someone
tell how it can be done with php...
many thanks.
<?php
$page=1;
$nor=5;
$a=1;
if(isset($_GET['page']))
{
}
else
{
$_GET['page']=1;
}
echo $_GET['page'];
$con=mysql_connect("localhost","root","")
or die ("error");
$db=mysql_select_db("check",$con)
or die("database not found");
$result=mysql_query("SELECT * FROM comment")
or die ("query error");
echo "<table border='1'><tr><th>name</th><th>Comment</th></tr>";
$r=mysql_num_rows($result);
echo $r."<br/>";
$p=ceil($r/$nor);
//echo $p;
while($rows=mysql_fetch_array($result))
{
if($a>($_GET['page']-1)*$nor)
{
echo "<tr><td>".$rows['user']."</td><td>".$rows['comment']."</td></tr>";
}
$a=$a+1;
}
echo "</table>";
for($i=1;$i<=$p;$i++)
{
if($i==$_GET['page'])
{
echo $i;
}
else
{
echo "<a href='check.php?page=".$i."'>".$i."</a>";
}
}
?>
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.