954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Filter Results through Dropdown List + Pagination Question

Hello!

I'd like to ask a question, and I guess the simplest way to explain what I want is to simply show you the page .

See the sort by list? I simply want to sort the entries by year, which I did succeed with, in a way. The problem is that I'm being forced to make a new identical PHP page for each year, where I change the query to sort by the chosen year. The pages are linked from the dropdown list. Which is an awful way of doing it, since if I ever want to edit the page, I have to edit all the year copy pages too. :/

Is there a way to sort entries that doesn't require me to make a new php page, and just keeps it all on page one, so to speak? And if this is possible, how do you make the pagination adapt to it? Since the way I have it now, it'd break if I didn't change the URL's in the code.

Thanks a lot in advance for any replies!

Note: I'm a beginner at this, so I hope the question isn't too silly. I've searched the net a lot, but I couldn't find anything directly related to my question. :/

Linlin
Newbie Poster
14 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

The dropdown should send a value to the page, e.g. 2009.
The page searches for this - by looking for $_POST['year'] (or whatever you've called the dropdown select field).
You now 'clean' this value and pass it to your sql statement:

$year = mysql_real_escape_string($_POST['year']);
$sql = "SELECT * FROM table WHERE year = '$year'";


Straightforward.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

The dropdown should send a value to the page, e.g. 2009. The page searches for this - by looking for $_POST['year'] (or whatever you've called the dropdown select field). You now 'clean' this value and pass it to your sql statement:

$year = mysql_real_escape_string($_POST['year']);
$sql = "SELECT * FROM table WHERE year = '$year'";

Straightforward.

I have to say I apparently have no idea how to actually implement that on my page. I can't get my list to work at all, heh. I'm not sure how that works with multiple years either. :/

Linlin
Newbie Poster
14 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Do you have any code to share with us? I'm loathe to provide a complete solution if you haven't got anything yourself. I'm willing to help, but not do ALL the work.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Uhm, like what code? The code for the entries to show up? Well, since I'm not sure how to implement the slice of code you gave me, I've just been experimenting a bit (like of which part of the page it goes, if I was supposed to replace my current query, make a second, mess with my list etc)... I guess I don't really understand how the list is supposed to pick up the information and make anything happen?

Linlin
Newbie Poster
14 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Can you show your html then?

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

For my dropdown, I guess?

Sort by year:
<form name="jump" action="http://lace.forthesky.org/wardrobe/angelicpretty/op" method='post'>
<fieldset>
<select name="x">
<option value="2010">2010</option>
<option value="2004">2004</option>
</select>
<input type="button" onclick="location=document.jump.x.options[document.jump.x.selectedIndex].value;" value="GO" />
</fieldset>
</form>

Linlin
Newbie Poster
14 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Or nevermind. I got the list to work, but then all default entries disappeared. Oh well. Thanks anyway.

Linlin
Newbie Poster
14 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: