In reading all the articles on pagination, I understand I need to pass variables into the resulting URL to allow for $REQUEST or $GET of the variables. But I have set up a dynamically generated SQL statement. What's the best approach to pass only the required variables?
As an example, I have set these variables which start out being posted from a form:
$PropertyType = (!isset($_GET['PropertyType']))? $_POST['PropertyType'] : $_GET['PropertyType'];
$priceMin = (!isset($_GET['priceMin']))? $_POST['priceMin'] : $_GET['priceMin'];
$priceMax = (!isset($_GET['priceMax']))? $_POST['priceMax'] : $_GET['priceMax'];
$bedrooms = (!isset($_GET['bedrooms']))? $_POST['bedrooms'] : $_GET['bedrooms'];
$bathrooms = (!isset($_GET['bathrooms']))? $_POST['bathrooms'] : $_GET['bathrooms'];
echo "PropertyType: " . $PropertyType . " - priceMin: " . $priceMin . " - priceMax: " . $priceMax;
echo "<br />Bedrooms: " . $bedrooms . " - Bathrooms: " . $bathrooms;
The user selects the following from the form and hits submit:
Residential property
3 bedrooms minimum
4 bathrooms minimum
$100,000 price min
$200,000 price max
On the initial post, variables are passed:
PropertyType: RES - priceMin: 100 - priceMax: 200
Bedrooms: 4 - Bathrooms: 3
On the $_GET for page 2, variables are lost, and user is prompted to fill in 2 form fields (textboxes for priceMin and priceMax). (part of the validation process)
The SQL query is dynamically generated; see attached file. There are lots of ifs based on the resulting PropertyType.
The pagination class I am using allows passing of variables, useage like:
$PaginateIt->SetQueryString('PropertyType='.$PropertyType.'&priceMin='.$priceMin.'&priceMax='.$priceMax);
If I want to pass exactly what is included in the sql statement and no more, is some form of http_build_query my answer?
Working Example (choose Option 2, search by address)
Dynamically generated SQL (choose Option 3, Search by Criteria)