...

View Full Version : query on submit (search and pagination problem)



_user
04-26-2012, 07:10 PM
I have a form
<select>
<option value="">Select color</option>
<option value="black">black</option>
<option value="red">red</option>
</select>

<select>
<option value="">Select size</option>
<option value="one">two</option>
<option value="two">two</option>
</select>

<input type="submit" value="Submit" name="submit" />






$color = $_GET['color'];
$size = $_GET['size'];

(...)

$query = "SELECT * FROM table WHERE color LIKE '%$color%' AND size LIKE '%$size%' LIMIT $start, $per_page ";

(...)


and the search link is something like this:
www.domain.com/file.php?color=black&size=two&submit=Submit

When paginating the results, when I click to page2 I get page2 with all the results from db (not the color and size selected on the search) and the link is something like this www.domain.com/file.php?page=2

How can I resolv this problem?
I searched and read about this problem for a while... but I can't find the solution.


Now I think to do a verification to run the query just when I click the submit button.

Something like this

<input type="hidden" name="searching" value="yes" />

and

if ($searching =="yes")

.


Any other ideea?

Fou-Lu
04-26-2012, 08:35 PM
You've simply lost your querystring. Where are you building the pagination links?

_user
04-27-2012, 06:29 AM
I have one more fields that I select and send me to different files.
So, I have file1.php, file2.php, file3.php.

I use include for the top part of page with the search form. So the search form is on every page.

The pagination is on file1.php (file2.php, and file3.php).
This are the results page. (Sorry if you asked something else).

Fou-Lu
04-27-2012, 03:41 PM
Yeah, where's the code for making the pagination links?

_user
04-27-2012, 03:47 PM
if($pages >= 1 && $page <= $pages){
for ($x=1; $x<=$pages; $x++){
$pagination .= ($x == $page) ? '<strong>' . $x . '</strong> ' : '<a href="?page=' .$x. '"> ' . $x . '</a> ';
}

}

this is the code.

Fou-Lu
04-27-2012, 04:51 PM
$x only represents the page number. You do not have enough information to pass along to other pages to use the search. Use this (you can unset anything from post you don't need in the $aQS):


$aQS = $_GET;
if ($pages >= 1 && $page <= $pages)
{
for ($x = 1; $x <= $pages; ++$x)
{
$aQS['page'] = $x;
$sQS = http_build_query($aQS);
$pagination .= ($x == $page) ? '<strong>' . $x . '</strong> ' : sprintf('<a href="%s">%s</a>', $sQS, $x);
}
}

_user
05-15-2012, 04:09 PM
still dosn't work :(

Fou-Lu
05-15-2012, 06:12 PM
What is the querstring passed by the links?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum