New to PHP, have seent several codes for pagination. The code below has all I want in the code. I run code I get results for first page, and subsequent href tags for pages. When I click on link it runs again inserted pg num and limit into the sql statement, but pg num is being reset to O or the pg num is not being stored or recalled. So I get, “No results found matching your query”.
[CODE] the query.
$numrows = mysql_num_rows($numresults);
if ($numrows == 0){
echo(“No results found matching your query – $query”); // bah, modify the “Not Found” error for your needs.
exit();}
You can view the php page in action by following this link, [url]www.historiccharlestonsc.net/accomodations/accomodations.html
The complete code is as follows: (I omitted the actual db name and passwords.)
[CODE]
</head>
<?php
// declare variables
$city= $_POST[location];
$accommodationstype=$_POST[accomodations_type];
$roomrates= $_POST[room_rates];
$theme=$_POST[theme];
$dining=$_POST[dining];
$breakfast=$_POST[breakfast];
$roomservice=$_POST[room_service];
$pool=$_POST[pool];
$gym=$_POST[gym];
$spaservices=$_POST[spa_services];
$airportpickup=$_POST[airport_pickup];
$internetaccess=$_POST[internet_access];
$businesscenter=$_POST[business_center];
$banquetfacilities=$_POST[banquet_facilities];
$conferencerooms=$_POST[conference_rooms];
$meetingrooms=$_POST[meeting_rooms];
$frontdesk=$_POST[front_desk];
$parking=$_POST[parking];
$petfriendly=$_POST[pet_friendly];
$conciergeservices=$_POST[concierge_services];
$rating=$_POST[rating];
if (!isset($_POST[‘submit’]))
$localhost=”######”; //the name of the host
$dbname=”########”; // the name of the database
$dbsearch=”##############”; // user name
$dbpass=”##########################”; // password
$results = mysql_query;
// connect to mysql server on inmotionhosting
$db=mysql_connect($localhost, $dbsearch, $dbpass) or die(“Connection Failure to Database”); //(host, username, password)
// select correct db histor28_data from mysql server
mysql_select_db($dbname, $db) or die ($dbname . ” <p><font size=”+3″>Unable to connect to the database server.</font></p>. ” . $dbsearch);
if (!($db)) // If no connect, error and exit().
{
echo( “<p><font size=”+3″>Unable to connect to the database server.</font></p>”);
exit();
}
if (!(@mysql_select_db($dbname))) // If can’t connect to database, error and exit().
{
echo(“<p>Unable to locate the $db_name database.</p>”);
exit();
}
if (!($page)){
$page = 0;} // Default page value.
if (!($limit)){
$limit = 10;} // Default results per-page.
$numresults = mysql_query(“SELECT name, address, city, gps, accomodations_type, reviewadd, webadd, reservation_page, map, room_rates, pmt_methods, description, logo, theme, pool, gym, internet_access, dining, breakfast, airport_pickup, recommended, banquet_facilities, parking, front_desk, spa_services, room_service, business_center, conference_rooms, meeting_rooms, concierge_services, pet_friendly, rating, amenities FROM `hoteldata` WHERE city like ‘$city’ and accomodations_type like ‘$accommodationstype’ and rating like ‘$rating’ and room_rates like ‘$roomrates’ and theme like ‘$theme’ “); // the query.
$numrows = mysql_num_rows($numresults);
if ($numrows == 0){
echo(“No results found matching your query – $query”); // bah, modify the “Not Found” error for your needs.
exit();}
$pages = intval($numrows/$limit); // Number of results pages.
// $pages now contains int of pages, unless there is a remainder from division.
if ($numrows%$limit) {
$pages++;} // has remainder so add one page
$current = ($page/$limit) + 1; // Current page number.
if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
else {
$total = $pages;} // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
else{
$last = $numrows;} // If last results page, last result equals total number of results.
//escape from PHP mode.
?>
<!– end Search by multi categories –>
</head>
<body>
<div id=”header”>
<div id=”splash”>
<div id=”logo”><a href=”http://www.historiccharlestonsc.net/index.html” title=”Historic Charleston Harbor”><strong>Historic Charleston SC</strong></a>.net</div>
<div id=”navigation”><a href=”http://www.historiccharlestonsc.net/index.html”><img src=”http://www.historiccharlestonsc.net/images/historiccharlestonbanner.jpg” alt=”Historic Charleston Harbor” width=”950″ height=”160″ id=”arthurravenelbridge” name=”arthurravenelbridge” /></a><br />
</div>
</div>
</div>
<div id=”wrapper”>
<div id=”page”>
<div id=”content”>
<br />
<table width=”480″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td align=”center” bgcolor=”#333333″><font size=”+2″><?=$numrows?> Search Results Found</font><br /><br /></td>
</tr>
<tr>
<td align=”left” bgcolor=”#333333″> Page –
<?
if ($page != 0) { // Don’t show back link if current page is first page.
$back_page = $page – $limit;
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$back_page&limit=$limit”>back</a> n”);}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i – 1);
if ($ppage == $page){
echo(“<b>$i</b> n”);} // If current page don’t give link, just text.
else{
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$ppage&limit=$limit”>$i</a> n”);}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don’t give next link.
$next_page = $page + $limit;
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$next_page&limit=$limit”>next</a>n”);}
?>
</td>
</tr>
<tr>
<td align=”right” bgcolor=”#333333″>
Results per-page: <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5″>5</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10″>10</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20″>20</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50″>50</a> <br /><br /></td></tr></table>
<?php
$results = mysql_query(“SELECT name, address, city, gps, accomodations_type, reviewadd, webadd, reservation_page, map, room_rates, pmt_methods, description, logo, theme, pool, gym, internet_access, dining, breakfast, airport_pickup, recommended, banquet_facilities, parking, front_desk, spa_services, room_service, business_center, conference_rooms, meeting_rooms, concierge_services, pet_friendly, rating, amenities FROM `hoteldata` WHERE city like ‘$city’ and accomodations_type like ‘$accommodationstype’ and rating like ‘$rating’ and room_rates like ‘$roomrates’ and theme like ‘$theme’ ORDER by name ASC LIMIT $page, $limit”); // the query.
echo “<table width=”480″ border=”1″ cellpadding=”15″ cellspacing=”0″>”;
while ($row = mysql_fetch_array($results))
{
echo “<tr>”;
echo “<td bgcolor=”#333333″ width=”75px” align=”left”><img src=$row[logo]><br /><h5>Property Type:<br />$row[accomodations_type]<br /><br />
Theme:<br />$row[theme]<br /><br />
$row[webadd]<br /><br />
</h5><img src=$row[pmt_methods]></td>”;
echo “<td bgcolor=”#333333″><p align=”center”><h4>$row[name]</h4>
$row[address], $row[city]<br /><br /></p>
<p>| <A HREF=$row[reviewadd]
onClick=”return popup(this, ‘notes’)”>Review</a> | <a href=$row[amenities]
onClick=”return popup(this, ‘notes’)”>Amenities</a> | <a href=$row[map]
onClick=”return popup(this, ‘notes’)”>Map</a> | <a href=$row[reservation_page]
onClick=”return popup(this, ‘notes’)”>Reservations</a> |</p>
<h5 align=”left”>$row[description]</h5>
<h6 align=”left”>$row[recommended]</h6></td>”;
echo “</tr>”;
}
echo “</table>”;
?>
<table width=”480″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td bgcolor=”#333333″ align=”left”><br /> Page –
<?
if ($page != 0) { // Don’t show back link if current page is first page.
$back_page = $page – $limit;
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$back_page&limit=$limit”>back</a> n”);}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i – 1);
if ($ppage == $page){
echo(“<b>$i</b> n”);} // If current page don’t give link, just text.
else{
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$ppage&limit=$limit”>$i</a> n”);}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don’t give next link.
$next_page = $page + $limit;
echo(“<a href=”http://www.historiccharlestonsc.net/php/hoteldatasearch11.php?query=$query&page=$next_page&limit=$limit”>next</a>n”);}
?>
</td>
<tr>
<td align=”right” bgcolor=”#333333″>
Results per-page: <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5″>5</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10″>10</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20″>20</a> | <a href=”<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50″>50</a> <br /><br /></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
I just don’t know enough to figure out what I am doing wrong.
Thanks.