Jump to content

Recommended Posts

I want visitors to be able to sort the results on my Browse Documentaries page by popularity, date, and type. The only way I know how to do this is to create a separate page for each sorting arrangement and provide a link to each page. Is there any way of doing it on a single page?

 

I am guessing that I can do things like that with Javascript or jQuery. Is that correct?

This could potentially be accomplished using JavaScript / jQuery. My preference would be to use PHP though. If you can use PHP, you could build an HTML form (or some selection mechanism) that allows visitors to choose how the videos are sorted. The form would submit to the same page and display the videos again. But this time, you'll have a GET or POST variable which says how to sort the videos. That variable could be used in a database query so that the videos are sorted based on the chosen option.

 

Once you get that figured out, you'll need to determine how you'll pass the sort-order flag through the rest of your pagination links. You could embed the flag as a GET variable, utilize SESSION variables, etc.

  • Like 1

you would make links that contain a get parameter that tells your one page how you want to sort the data, such as ?sort=date&direction=asc

 

you would then test for and validate the get parameters and use the values to determine what sql query statement to build (don't use the values directly in a query without being fully validated to insure they are ONLY one of the permitted values in order to prevent sql injection.) you would also build the pagination links with whatever existing get parameters there (you can use http_build_query to do this) are so that they propagate between the page requests when you click on the pagination links.

  • Like 1

I think I get it:

  1. I'll construct a simple HTML form with radio buttons and a Submit button and put it on the page.
  2. Visitors will be able to select from the options and submit the form to the same page.
  3. The page will "GET" the parameters from the URL and create the SQL statements to be used in selecting the content and building the pagination.

Does that sound right?

 

But there's something that's confusing me.

 

I have used mod_rewrite to rewrite my URLs. At the moment, to visitors, the URL of my Browse page looks like this:

 

/browse/page_number

 

But the actual URL looks like this:

 

/browsevideos.php?page=page_number

 

I want to give visitors 3 content options:

  1. videos and documentaries
  2. just videos
  3. just documentaries.

I also want to give them 3 sorting options:

  1. newest-oldest
  2. oldest-newest
  3. popularity.

This means that there will be 9 possible arrangements of the content, and each arrangement will have its own URL, for example:

 

/browsevideos.php?content=justvideos&sort=newest_oldest&page=page_number

 

I then have to rewrite the URLs, for example:

 

browse/videosanddocumentaries/newest-oldest/page_number

browse/videosanddocumentaries/oldest-newest/page_number

browse/videosanddocumentaries/popular-unpopular/page_number

 

browse/justvideos/newest-oldest/page_number

browse/justvideos/oldest-newest/page_number

browse/justvideos/popular-unpopular/page_number

 

browse/justdocumentaries/newest-oldest/page_number

browse/justdocumentaries/oldest-newest/page_number

browse/justdocumentaries/popular-unpopular/page_number

 

Is that correct?

 

If so, what are the consequences for SEO? Wouldn't there be duplicate content issues?

I think I get it:

I'll construct a simple HTML form with radio buttons and a Submit button and put it on the page.

Visitors will be able to select from the options and submit the form to the same page.

The page will "GET" the parameters from the URL and create the SQL statements to be used in selecting the content and building the pagination.

Does that sound right?

 

 

yes, and for those that have javascript enabled, you can use an onchange event to submit the filter form. for those without javascript, provide a submit button using <noscript></noscript> tags.

 

i would reverse the order of the fields in the rewritten url. you will always have a page number, even if there's only one page. the page number should come first. the content and sort type won't necessarily exist and should come after the page number.

  • Like 1

Thanks, mac_gyver and cyberRobot! ;D

 

I think I know what to do now.

 

But I can't help but think that it would be easier to just create the pages individually.

 

Is there any benefit to doing it all on one page?

But I can't help but think that it would be easier to just create the pages individually.

 

Is there any benefit to doing it all on one page?

Yes. What if something changes, like you add a new feature.  Would you like to update 1 page of code or 9? You'd be basically duplicating code 9 times with small variances which is not what programmers should do. This is like saying you shouldn't have pagination and manually create 1 file for each page.

 

Do you really need to rewrite the url for this part? Why not keep that part a querystring?

/browse/1?category=video-documentaries&order=popularity

 

Also, since you have newest-oldest (descending), oldest-newest (ascending)...why wouldn't you do the same for popularity?

  • Like 1

Yes. What if something changes, like you add a new feature.  Would you like to update 1 page of code or 9? You'd be basically duplicating code 9 times with small variances which is not what programmers should do. This is like saying you shouldn't have pagination and manually create 1 file for each page.

 

Do you really need to rewrite the url for this part? Why not keep that part a querystring?

/browse/1?category=video-documentaries&order=popularity

 

Also, since you have newest-oldest (descending), oldest-newest (ascending)...why wouldn't you do the same for popularity?

Good points!

 

The thing that was disuading me from doing it all on one page was that, once I rewrite the URLs, they would seem like 9 separate pages anyway, all with the same content, albeit arranged in a different order. I therefore thought, Why not just do 9 separate pages? It would actually be easier. I didn't realise that I didn't have to rewrite the URLs to hide the querystring.

 

Thanks for that!

 

Yes, by "popularity", I meant from most popular to least popular.

 

Thanks for the help, gentlemen.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.