Home »
Imported messages »
comp.lang.php »
pagination driving me insane
pagination driving me insane [message #174607] |
Tue, 21 June 2011 21:22 |
Co
Messages: 75 Registered: May 2011
Karma:
|
Member |
|
|
Hi All,
I have a page which displays accounts. On the page there are three
search options:
1. sort by newest members first;
2. search by country;
3. search by name;
There is a limit of 10 accounts per page. If the query returns more
than 10 records I have to browse to the next page.
So I need to save the search options in the url when I go to the next
page. I tried the following code but it doesn't work properly:
// check if any of the three buttons were clicked
if(isset($_POST['listByq']) {
// did I click the search by country button
if ($_POST['listByq'] == "by_country") {
$value = $_POST['country']; //put the country name in the
variable for the URL
$country = $_POST['country'];
$queryString = "WHERE country='$country' AND email_activated='1'";
$choice = $_POST['listByq']; } //put by_country in the variable
for the URL
// did I click on the searh by firstname
else if ($_POST['listByq'] == "by_firstname") {
$value = $_POST['fname'];
$firstname = $_POST['fname'];
$firstname = mysql_real_escape_string($firstname);
$queryString = "WHERE firstname LIKE '%$firstname%' OR lastname
LIKE '%$firstname%' AND email_activated='1'";
$choice = $_POST['listByq'];
// or did I click the newest members first sort order
} else if ($_POST['listByq'] == "newest_members") {
$value = "";
$queryString = "WHERE email_activated='1' ORDER BY id DESC";
$choice = $_POST['listByq'];
}
}
// now get the values form the URL
if (isset($_GET['choice'])) {
$choice = $_GET['choice'];
$value = $_GET['value'];
}
// if there was anything in $choice
if ($choice <> "") {
if($choice = "by_country") {
$country = $value;
$queryString = "WHERE country='$country' AND
email_activated='1'";
else if ($choice= "by_firstname") {
$firstname = $value;
$queryString = "WHERE firstname LIKE '%$firstname%' OR lastname
LIKE '%$firstname%' AND email_activated='1'";
$queryMsg = "Showing Members with the name you searched for"; }
else if ($choice= "newest_members") {
$queryString = "WHERE email_activated='1' ORDER BY id DESC";
}
}
The pagination looks like this:
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' .
$add1 . '&choice=' . $choice . '&value=' . $value . '">' . $add1 . '</
a> ';
I know there must be a solution for this which works but I have looked
at it from all sides but I don't get it.
Does anyone know how to get this working?
Marco
|
|
|
Goto Forum:
Current Time: Fri Nov 08 16:27:26 GMT 2024
Total time taken to generate the page: 0.27145 seconds