|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2000-08-15 11:49 UTC] joey@php.net
[2005-03-31 16:13 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 07:00:01 2025 UTC |
hi there, I would like to display my data from my postgresql database on my html file but the data is alot to be display on one page so I want to display it on several pages, so am using next to link to the next page to view the data, but when I click next, or one of the links it does not display from the specified row, please assist on this thanks. best regards Martin Kuria below is my code please assist,. <html> <body> <?php $conn = pg_connect( "host=localhost user=postgres password=martinmw dbname=kenyellowpages"); if (!$conn) { echo "An error occured.\n"; exit; } $sql_text= "SELECT * FROM orgdetails1 WHERE lower(orgname) LIKE lower('$orgname%') AND lower(catparent) LIKE lower('$catparent%') AND lower(cityid) LIKE '$cityid%';"; $per_page = 5; if (!$page) { $page = 1; } $prev_page = $page - 1; $next_page = $page + 1; //$query = mysql_query($sql_text); $result_set = pg_Exec($conn, $sql_text); //Set up specified page $page_start = ($per_page + $page) - $per_page; //$num_rows = mysql_num_rows($query); $num_rows = pg_NumRows($result_set); if ($num_rows <= $per_page) { $num_pages = 1; } else if (($num_rows % $per_page) == 0) { $num_pages = ($num_rows / $per_page); } else { $num_pages = ($num_rows / $per_page) + 1; } $num_pages = (int) $num_pages; if (($page > $num_pages) || ($page < 0)) { error("You have specified an invalid page number"); } // Now the pages are set right, we can // perform the actual displaying... $sql_text1= "SELECT * FROM orgdetails1 WHERE lower(orgname) LIKE lower('$orgname%') AND lower(catparent) LIKE lower('$catparent%') AND lower(cityid) LIKE '$cityid%' limit $page_start,$per_page;"; //$sql_text = $sql_text." LIMIT $page_start,$per_page "; //$query = mysql_query($sql_text); $result_set1 = pg_Exec($conn, $sql_text); $num_rows1 = pg_NumRows($result_set1); for ($j=0; $j < $num_rows1; $j++) { $pos = pg_result($result_set, $j, "orgname"); $pos2 = pg_result($result_set, $j, "postadd"); $pos3 = pg_result($result_set, $j, "phadd"); $pos4 = pg_result($result_set, $j, "tel"); $pos5 = pg_result($result_set, $j, "fax"); $pos6 = pg_result($result_set, $j, "email"); $pos7 = pg_result($result_set, $j, "website"); $pos8 = pg_result($result_set, $j, "cityid"); $pos9 = pg_result($result_set, $j, "catid"); $pos10 = pg_result($result_set,$j, "catparent"); $pos11 = pg_result($result_set,$j, "id"); /*while ($result = pg_fetch_array($result_set1)) { // This stuff is obviously just an example. This is where you want // to layout your HTML to display the queries. This loop will run // once for every entry to be displayed on the current page. echo "$result[orgname]"; echo "<br>";*/ echo "<center>"; echo "<table width=90% bgcolor=#ffffff cellpadding=0 cellspacing=2 border=0>"; echo "<tr> <td align=Left BGCOLOR=#efefef colspan=3> <ul><li> <font size=-2 face=Verdana, Arial, Helvetica, sans-serif color=#000000> <a href=yellowmustall.php3?id=$pos11&catid=$pos9> $pos </a> <font size=-2>$pos2</font> </li></ul> </td> </tr></table></center>"; } // Previous if ($prev_page) { echo "<a href=\"$PHP_SELF?page=$prev_page&cityid=$pos8&catid=$pos9&catparent=$pos10\">Prev</a> "; } // Page # direct links // If you don't want direct links to each page, you should be able to // safely remove this chunk. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $page) { echo " <a href=\"$PHP_SELF?page=$i&cityid=$pos8&catid=$pos9&catparent=$pos10\">$i</a> "; } else { echo " $i "; } } // Next if ($page != $num_pages) { echo "<a href=\"$PHP_SELF?page=$next_page&cityid=$pos8&catid=$pos9&catparent=$pos10\">Next</a>"; } ?> </body></html>