Hello everyone,
I'm trying to develop a code for a website. I need your help. I'm trying to write a code for displaying the results for a search in multiple pages....for e.g., if there are 54 records for my search then the result should be displayed in 3 pages with first page containing 25 records, 2nd with 25 records and the last with the remaining.....
I'm copying my code here...pls let me know the changes i've to make so that it works...
<?php
$dbconn = pg_connect("host=localhost dbname=usa user=postgres password=savita");
echo "::: ";
if($dbconn){
echo "Connection established<br>";}
else{
echo "Connection not established<br>";}
$a=$POST[t2];
$b=$POST[t3];
$c=$_POST[t1];
echo "<center><h2>Search Results for $a in $b</center><br>";
$rows_per_page = 25;
$query="SELECT * from $c WHERE (cat1 ilike '$a%' or bname ilike '$a%') and (city ilike '$b%' or zip='$b')";
$result=pg_query($query) or die('Query failed:' . pg_last_error());
$total_records = pg_numrows($result);
$pages = ceil($total_records / $rows_per_page);
echo "<br>$total_records<br>";
echo "<br>$pages<br><br>";
if (!isset($screen))
$screen = 0;
$start = $screen * $rows_per_page;
$query="SELECT * from $c WHERE (cat1 ilike '$a%' or bname ilike '$a%') and (city ilike '$b%' or zip='$b') LIMIT 25";
$result=pg_query($query) or die('Query failed:' . pg_last_error());
echo "<table border=1>";
for ($lt = 0; $lt < pg_numrows($result); $lt++)
{
echo "\t<tr>\n";
$cat1 = pg_result($result, $lt, 0);
$cat2 = pg_result($result, $lt, 1);
$bname = pg_result($result, $lt, 2);
$staddress = pg_result($result, $lt, 3);
$city = pg_result($result, $lt, 4);
$state = pg_result($result, $lt, 5);
$zip = pg_result($result, $lt, 6);
$phone = pg_result($result, $lt, 7);
$fax = pg_result($result, $lt, 8);
// print results
//print("You inserted: <br />");
//print("<hr /><br />");
print("<td>$bname</td>");
print("<td>$staddress</td>");
print("<td>$city</td>");
print("<td>$state</td>");
print("<td>$zip</td>");
print("<td>$phone</td>");
print("<td>$fax</td>");
echo "\t</tr>\n";
}
echo "</table>";
echo "<p><hr></p>\n";
// let's create the dynamic links now
if ($screen > 0) {
$url = "next1.php?screen=" . $screen - 1;
echo "<a href=\"$url\">Previous</a>\n";
}
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
$url = "next1.php?screen=" . $i;
echo " | <a href=\"$url\">$i</a> | ";
}
if ($screen < $pages) {
$url = "next1.php?screen=" . $screen + 1;
echo "<a href=\"$url\">Next</a>\n";
}
?>
This code is displaying the first 25 records but it is not displaying the other records in the next pages.
PLZ GUYS THIS IS URGENT.