This is driving me nuts!! Thanks to those who have added valuable input so far.
Has anybody got the time to run this on their test box and see if you get the same problem.
[LEFT][COLOR=#808080][I]-- phpMyAdmin SQL Dump[/I][/COLOR]
[COLOR=#808080][I]-- version 3.3.1[/I][/COLOR]
[COLOR=#808080][I]-- http://www.phpmyadmin.net[/I][/COLOR]
[COLOR=#808080][I]--[/I][/COLOR]
[COLOR=#808080][I]-- Host: localhost[/I][/COLOR]
[COLOR=#808080][I]-- Generation Time: Aug 12, 2010 at 03:17 PM[/I][/COLOR]
[COLOR=#808080][I]-- Server version: 5.1.47[/I][/COLOR]
[COLOR=#808080][I]-- PHP Version: 5.3.2[/I][/COLOR]
[COLOR=#993333][B]SET[/B][/COLOR] SQL_MODE=[COLOR=#FF0000]"NO_AUTO_VALUE_ON_ZERO"[/COLOR];
[COLOR=#808080][I]/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */[/I][/COLOR];
[COLOR=#808080][I]/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */[/I][/COLOR];
[COLOR=#808080][I]/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */[/I][/COLOR];
[COLOR=#808080][I]/*!40101 SET NAMES utf8 */[/I][/COLOR];
[COLOR=#808080][I]--[/I][/COLOR]
[COLOR=#808080][I]-- Database: `form`[/I][/COLOR]
[COLOR=#808080][I]--[/I][/COLOR]
[COLOR=#808080][I]-- --------------------------------------------------------[/I][/COLOR]
[COLOR=#808080][I]--[/I][/COLOR]
[COLOR=#808080][I]-- Table structure for table `test`[/I][/COLOR]
[COLOR=#808080][I]--[/I][/COLOR]
[COLOR=#993333][B]CREATE TABLE[/B][/COLOR] IF [COLOR=#AA3399][B]NOT[/B][/COLOR] [COLOR=#993333][B]EXISTS[/B][/COLOR] `test` [COLOR=#66CC66]([/COLOR]
`city` [COLOR=#AA9933][B]VARCHAR[/B][/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]50[/COLOR][COLOR=#66CC66])[/COLOR] [COLOR=#AA3399][B]NOT NULL[/B][/COLOR],
`property_type` [COLOR=#AA9933][B]VARCHAR[/B][/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]50[/COLOR][COLOR=#66CC66])[/COLOR] [COLOR=#AA3399][B]NOT NULL[/B][/COLOR],
`id` [COLOR=#AA9933][B]INT[/B][/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]10[/COLOR][COLOR=#66CC66])[/COLOR] [COLOR=#AA3399][B]NOT NULL[/B][/COLOR] [COLOR=#AA3399][B]AUTO_INCREMENT[/B][/COLOR],
`summary` [COLOR=#AA9933][B]VARCHAR[/B][/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#CC66CC]100[/COLOR][COLOR=#66CC66])[/COLOR] [COLOR=#AA3399][B]NOT NULL[/B][/COLOR],
`status` [COLOR=#AA9933][B]TEXT[/B][/COLOR] [COLOR=#AA3399][B]NOT NULL[/B][/COLOR],
[COLOR=#993333][B]PRIMARY KEY[/B][/COLOR] [COLOR=#66CC66]([/COLOR]`id`[COLOR=#66CC66])[/COLOR]
[COLOR=#66CC66])[/COLOR] ENGINE=[COLOR=#993333][B]INNODB[/B][/COLOR] [COLOR=#AA3399][B]DEFAULT[/B][/COLOR] [COLOR=#AA3399][B]CHARSET[/B][/COLOR]=latin1 [COLOR=#AA3399][B]AUTO_INCREMENT[/B][/COLOR]=[COLOR=#CC66CC]14[/COLOR] ;
[COLOR=#808080][I]--[/I][/COLOR]
[COLOR=#808080][I]-- Dumping data for table `test`[/I][/COLOR]
[COLOR=#808080][I]--[/I][/COLOR]
[COLOR=#993333][B]INSERT[/B][/COLOR] [COLOR=#993333][B]INTO[/B][/COLOR] `test` [COLOR=#66CC66]([/COLOR]`city`, `property_type`, `id`, `summary`, `status`[COLOR=#66CC66])[/COLOR] [COLOR=#993333][B]VALUES[/B][/COLOR]
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'Ashford'[/COLOR], [COLOR=#FF0000]'Apartment'[/COLOR], [COLOR=#CC66CC]1[/COLOR], [COLOR=#FF0000]'Apartment Ashford'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'Dover'[/COLOR], [COLOR=#FF0000]'Apartment'[/COLOR], [COLOR=#CC66CC]2[/COLOR], [COLOR=#FF0000]'Apartment Dover'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'Canterbury'[/COLOR], [COLOR=#FF0000]'Apartment'[/COLOR], [COLOR=#CC66CC]3[/COLOR], [COLOR=#FF0000]'Apartment Canterbury'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'Felixstowe'[/COLOR], [COLOR=#FF0000]'Apartment'[/COLOR], [COLOR=#CC66CC]4[/COLOR], [COLOR=#FF0000]'Apartment Felixstowe'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'Burnley'[/COLOR], [COLOR=#FF0000]'Apartment'[/COLOR], [COLOR=#CC66CC]5[/COLOR], [COLOR=#FF0000]'Apartment Burnley'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'Bristol'[/COLOR], [COLOR=#FF0000]'Apartment'[/COLOR], [COLOR=#CC66CC]6[/COLOR], [COLOR=#FF0000]'Apartment Bristol'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'Cowdenbeath'[/COLOR], [COLOR=#FF0000]'Apartment'[/COLOR], [COLOR=#CC66CC]7[/COLOR], [COLOR=#FF0000]'Apartment Cowdenbeath'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'Bristol'[/COLOR], [COLOR=#FF0000]'Villa'[/COLOR], [COLOR=#CC66CC]8[/COLOR], [COLOR=#FF0000]'Villa Bristol'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'Canterbury'[/COLOR], [COLOR=#FF0000]'Villa'[/COLOR], [COLOR=#CC66CC]9[/COLOR], [COLOR=#FF0000]'Villa Canterbury'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'New York'[/COLOR], [COLOR=#FF0000]'Villa'[/COLOR], [COLOR=#CC66CC]10[/COLOR], [COLOR=#FF0000]'New York Villa'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'Madrid'[/COLOR], [COLOR=#FF0000]'Villa'[/COLOR], [COLOR=#CC66CC]11[/COLOR], [COLOR=#FF0000]'Madrid Villa'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'Sydney'[/COLOR], [COLOR=#FF0000]'Villa'[/COLOR], [COLOR=#CC66CC]12[/COLOR], [COLOR=#FF0000]'Sydney Villa'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR],
[COLOR=#66CC66]([/COLOR][COLOR=#FF0000]'London'[/COLOR], [COLOR=#FF0000]'Villa'[/COLOR], [COLOR=#CC66CC]13[/COLOR], [COLOR=#FF0000]'London Villa'[/COLOR], [COLOR=#FF0000]'Y'[/COLOR][COLOR=#66CC66])[/COLOR];
[/LEFT]
Submit.php
<?php include("includes/conn.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Test</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
</body>
<!-- Start Search Bar -->
<div id="search-bar">
<form method="post" action="results.php">
<span class="search-text">Property Search:</span>-
Location:
<select name="city">
<option value="">No Preference</option>
<option value="Ashford">Ashford</option>
<option value="Bristol">Bristol</option>
<option value="Burnley">Burnley</option>
<option value="Canterbury">Canterbury</option>
<option value="Cowdenbeath">Cowdenbeath</option>
<option value="Dover">Dover</option>
<option value="Felixstowe">Felixstowe</option>
<option value="London">London</option>
<option value="Madrid">Madrid</option>
<option value="New York">New York</option>
<option value="Sydney">Sydney</option>
</select>
Property Type:
<select name="property_type">
<option value="">No Preference</option>
<option value="Apartment">Apartment</option>
<option value="Villa">Villa</option>
</select>
<input type="image" name="submit" class="btn" src="images/go_button_orange.gif" alt="Search Properties" />
</form>
</div>
<!-- End Header -->
</html>
Results.php
<?php
include("includes/conn.php");
//------------------------------------------------------------------------------
//-- Pagination Class
//------------------------------------------------------------------------------
class paginate
{
static function render($params, $current_page, $max_pages, $pages, $url = '')
{
if(!empty($url))
{
$url = explode('?', $url);
$url = $url[0];
}
unset($params['p']);
$query = http_build_query($params);
$query = strlen($query) ? '&' . $query : '';
$paginated = '';
//----------------------------------------------------------------------
//-- Previous Pages
//----------------------------------------------------------------------
if ($current_page > 0)
{
$paginated .= '<a class="pagenumber" href="' . $url . '?p=0' . $query . '">First Page</a>';
$pagi_limit = $current_page - $max_pages;
$pagi_limit = ($pagi_limit > 0) ? $pagi_limit : 0;
foreach(range($pagi_limit, ($current_page - 1)) as $i)
{
$paginated .= ' <a class="pagenumber" href="' . $url . '?p=' . $i . $query . '">' . ($i + 1) . '</a> ';
}
}
//----------------------------------------------------------------------
//-- Current Pages
//----------------------------------------------------------------------
$paginated .= ' <strong class="pagenumberhighlight">' . ($current_page + 1) . '</strong> ';
//----------------------------------------------------------------------
//-- Next Pages
//----------------------------------------------------------------------
if ($current_page < $pages)
{
$pagi_limit = $current_page + $max_pages;
$pagi_limit = ($pagi_limit < $pages) ? $pagi_limit : $pages;
for($i = $current_page + 1; $i < $pagi_limit; $i++)
{
$paginated .= ' <a class="pagenumber" href="' . $url . '?p=' . $i . $query . '">' . ($i + 1) . '</a> ';
}
if($current_page + 1 != $pagi_limit)
{
$paginated .= ' <a class="pagenumber" href="' . $url . '?p=' . ($pages - 1) . $query . '">Last Page</a> ';
}
}
return $paginated;
}
}
//------------------------------------------------------------------------------
//-- Pagination Settings
//------------------------------------------------------------------------------
$current_page = (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 0;
$per_page = (isset($_REQUEST['perpg'])) ? intval($_REQUEST['perpg']) : 3;
$max_pages = 5; // only should 5 pages left or right
//------------------------------------------------------------------------------
//-- Wheres
//------------------------------------------------------------------------------
$where = array();
if(!empty($_POST['city']))
{
// Allow only alphabetic characters
$param = preg_replace('/[^a-zA-Z ]/', '', $_POST['city']);
$param = mysql_real_escape_string($param);
$where []= "city = '$param'";
}
if(!empty($_POST['property_type']))
{
// Allow only alphabetic characters
$param = preg_replace('/[^a-zA-Z ]/', '', $_POST['property_type']);
$param = mysql_real_escape_string($param);
$where []= "property_type = '$param'";
}
$where = (!empty($where)) ? ' WHERE ' . implode(' AND ', $where) : '';
//------------------------------------------------------------------------------
//-- Orders
//------------------------------------------------------------------------------
$by = ($_GET['by'] == 'asc') ? 'ASC' : 'DESC';
switch($_GET['order']) {
case 'city':
$order = 'city';
break;
default:
$order = 'id';
$by = 'DESC';
break;
}
if($order and $by) {
$orderby = 'ORDER BY ' . $order . ' ' . $by;
}
//------------------------------------------------------------------------------
//-- Get Properties
//------------------------------------------------------------------------------
$limit_start = ($current_page * $per_page);
$limit_end = $per_page;
$result = mysql_query("SELECT * FROM test
$where
$orderby
LIMIT $limit_start, $limit_end"
);
if (!$result) {
echo 'Invalid query: ', mysql_error(), ' <br />';
}
$properties = array();
while ($property = mysql_fetch_assoc($result))
{
$properties []= $property;
}
//-- Get Total
$result = mysql_query("SELECT COUNT(*) AS total FROM test $where");
$total = array();
while($row = mysql_fetch_assoc($result))
{
$total = $row;
}
$total = $total['total'];
$pages = ceil($total / $per_page);
//------------------------------------------------------------------------------
//-- Get Pagination
//------------------------------------------------------------------------------
$pages = paginate::render($_GET, $current_page, $max_pages, $pages);
?>
<!-- Pagination -->
<?php echo $pages ?>
<?php foreach($properties as $property) { ?>
<p><?php echo htmlentities($property['summary']) ?></p>
<?php } ?>
<!-- Pagination -->
<?php echo $pages ?>
In desperation and frustration
Colin