I am unable to get code to display results on continuing pages. It will correctly count the number of results and actually display the first page. But when you select next or any one of the other page numbers you get the statement query not found. Anyone have any ideas why? Code below:
<head>
<?php
// get post from hotel search form
if(isset($_POST['submit']))
if(isset($_GET['go']))
$trimmed = trim($var); //trim whitespace from the stored variable
// 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];
$localhost="localhost"; //the name of the host
$dbname="database"; // the name of the database
$dbsearch="usedname"; // user name
$dbpass="password"; // password
$results="$row";
// 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 (!($limit)){
$limit = 10;} // Default results per-page.
if (!($page)){
$page = 0;} // Default page value.
$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 `table1` WHERE city like '$city' and accomodations_type like '$accommodationstype' and rating like '$rating' and room_rates like '$roomrates' and theme like '$theme' '%". $query ."%'"); // the query.
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
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.
?>
</head>
<body>
<span class="c1">Come stay with us</span><br />
<br />
<table width="480" border="1" cellpadding="15" cellspacing="0">
<tr>
<td align="center" bgcolor="#333333"><font size="+2">Search Results</font><br /><b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b></td>
</tr>
<tr>
<td bgcolor="#333333" colspan="2" align="left">Page -
<?
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?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.
{
$page = $limit*($i - 1);
if ($page = $page){
echo( "<b>$i</b> \n");} // If current page don't give link, just text.
else{
echo( "<a href=\"$PHP_SELF?query=$query&page=$page&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=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>");}
?>
</td>
</tr>
</table>
<?
// Now we can display results.
$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 `table1` WHERE city like '$city' and accomodations_type like '$accommodationstype' and rating like '$rating' and room_rates like '$roomrates' and theme like '$theme' '%". $query ."%' ORDER BY name ASC LIMIT $page, $limit");
Print "<table width=\"480\" border=\"1\" cellpadding=\"15\" cellspacing=\"0\">";
while ($row = mysql_fetch_array($results))
{
Print "<tr>";
Print "<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=.[pmt_methods].></td>";
Print "<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>";
Print "</tr>";
Print "</table>";
?>
<table width="480" border="1" cellpadding="15" cellspacing="0">
<tr>
<td bgcolor="#333333" colspan="2" align="right">Page -
<?
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo( "<a href=\"$PHP_SELF?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.
{
$page = $limit*($i - 1);
if ($page = $page){
echo( "<b>$i</b> \n");} // If current page don't give link, just text.
else{
echo( "<a href=\"$PHP_SELF?query=$query&page=$page&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=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a> \n");}
?>
</td>
</tr>
<tr>
<td bgcolor="#333333" align="right">
Results per-page: <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=30\>30</a> | <a href=<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=40>40</a>
</td>
</tr>
</table>
</body>
</html>