Keeping Drop-Down value to the next page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Iganorf
Forum Newbie
Posts: 10
Joined: Tue Dec 06, 2005 4:53 pm

Keeping Drop-Down value to the next page

Post 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.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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>";
Iganorf
Forum Newbie
Posts: 10
Joined: Tue Dec 06, 2005 4:53 pm

Post 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?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

posting the data are you...or simply using hyperlinks to go from one page to the next?
Iganorf
Forum Newbie
Posts: 10
Joined: Tue Dec 06, 2005 4:53 pm

Post 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.
Iganorf
Forum Newbie
Posts: 10
Joined: Tue Dec 06, 2005 4:53 pm

Post 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.
Post Reply