Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding GET parameter on url with a tag

I have a url that looks like this

mysite.com/index.php?page=home&gender=female&age=22

or

mysite.com/index.php?page=home&gender=female&occupation=programmer

How can I append a new parram orderby=value and order=asc using a tag like how the submit button works.

like when I click the link Name It will add new param on the link a I can sort the data by it

<a href="#">Name</a> | <a href="#">Age</a>

like how wordpresshandles it

wordpress/wp-admin/users.php?orderby=login&order=desc
like image 992
Cindy93 Avatar asked Jan 11 '23 18:01

Cindy93


1 Answers

Why don't you just build the URLs during the template render? No need for JS

eg

<a href="/index.php?occupation=programmer&orderby=name&order=desc">Name</a>

Just check the current order value when you render and invert it.

Obviously if you're using AJAX this is less useful.

like image 150
kinghfb Avatar answered Jan 16 '23 21:01

kinghfb