mysql_connect("localhost", "username", "$datapassword") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$query1 = "SELECT * FROM countries WHERE countryname LIKE '%a%'";
$result1 = mysql_query($query1) or die(mysql_error());
$num_rows1 = mysql_num_rows($result1);
echo "<h3>total returnd results $num_rows1 </h3>";
$start = $GET["start"];
$trow = $GET["trow"];
if ($start == "")
$start=0;
if ($trow == "")
$trow = 20;
$tpages = $num_rows1/$trow;
$tpages = $tpages+0.4;
//echo "$tpages </br>";
$tpages=round($tpages);
//echo "$tpages </br>";
FOR ($i = 1; $i <= $tpages; $i++)
{
if($i==1){
$pg=0;
}
else
{
$pg=$pg+$trow;
}
if ($start==$pg){
echo "$i ";
}
else
{
echo "<a href='pagemysql.php?start=$pg'>$i</a> ";
}
}
$query = "SELECT * FROM countries WHERE countryname LIKE '%a%' LIMIT $start , $trow";
$result = mysql_query($query) or die(mysql_error());
//$row = mysql_fetch_array($result) or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>code</th> <th>countryname</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo $row['code'];
echo "</td><td>";
echo $row['countryname'];
echo "</td></tr>";
}
echo "</table>";
mysql_close();
hope the above code helps you ๐