Page 1 of 1

Keeping Drop-Down value to the next page

Posted: Wed Dec 07, 2005 3:01 pm
by Iganorf
Okay, I have a page that displays entries obtained from a database, and I have it set to only allow 5 entries per page and you can click on each page number to see the other entries. Now I want to be able to sort my entries. I've already set up a form and my database is setup to order the entries by whatever I tell it to. The problem is that, for example you are looking at page #1 and you click to sort by price, it works fine, but when you click on page #2 it reverts back to the original order. Does anyone know where I can find the code to do this? I hope I haven't confused anyone. If you want to see what I'm talking about you can go to www.GarrettMcKone.com and click on the properties.

Posted: Wed Dec 07, 2005 3:34 pm
by Burrito

Code: Select all

echo "<select name=\"someSelect\">";
while($row = mysql_fetch_assoc($result))
{
    echo "<option value=\"".$row['someCol']."\" ".(isset($_POST['someSelect']) && $_POST['someSelect'] == $row['someCol'] ? "selected=\"selected\"" : "").">".$row['someCol']."</option>";
}
echo "</select>";

Posted: Wed Dec 07, 2005 4:40 pm
by Iganorf
Maybe I don't understand how to use your code, but my problem is not displaying the right options, or even selecting the right options. Every time that the page refreshes without the user clicking the submit button, ie when they click to go to the next page of entries, the form resets, causing the sorting to go back to the way it was before they used the form. Is there a way to carry their choice from page to page?

Posted: Wed Dec 07, 2005 4:43 pm
by Burrito
posting the data are you...or simply using hyperlinks to go from one page to the next?

Posted: Thu Dec 08, 2005 3:15 pm
by Iganorf
Yeah, when they click the "Go" button it submits the post, but they just link using hyperlinks to go to the next page of entries. Maybe I should make the hyperlinks also post data.

Posted: Thu Dec 08, 2005 3:34 pm
by Iganorf
Nevermind, thanks for all your help though. I just found out a way to do it by adding a couple of variables to the url. I had tried the same method earlier, but I must have made a mistake. Thanks alot.