ngreenwood6 Posted October 13, 2008 Share Posted October 13, 2008 I have created a table with a heading of date. The users will make an entry that gets saved into the database. I want them to be able to sort them by date by clicking on the date heading. Is there a name for this that I can google (for example pagination - i know thats not it but just so you know what I am looking for). The reason I ask is because I want to see if I can figure out how to do it on my own and if not I will come back for help. Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/ Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 I don't have the official name, if there is one up just look up "Sort column ascending/descending". Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-663995 Share on other sites More sharing options...
ngreenwood6 Posted October 13, 2008 Author Share Posted October 13, 2008 I will try that but in the mean time if anyone knows the name or if it is simple and can give an example all and any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-663998 Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 You need to make the column a link or have a link next to it. So the when you click on it it changes the query to ASC and when you click on it again it changes to DESC. You can just pass it through the URL with $_GET method. Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664007 Share on other sites More sharing options...
revraz Posted October 13, 2008 Share Posted October 13, 2008 Yep, just make the header row the link. Logic can be something like if it's already ASC, then make DESC, else ASC Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664011 Share on other sites More sharing options...
ngreenwood6 Posted October 13, 2008 Author Share Posted October 13, 2008 Thanks for the help I will try that. Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664019 Share on other sites More sharing options...
ngreenwood6 Posted October 13, 2008 Author Share Posted October 13, 2008 One more quick question. I am new to php and have been learning as much as I can but am still unfamiliar with some stuff. So my question is how can I append something to the end of the url if I don't know what is already going to be on the url. For example if the url already is: http://localhost/test.php?rows=10&page=1 How do I know what the url is to add something to it? If it was blank I could just add it like: ?sort=desc Any help is appreciated? Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664025 Share on other sites More sharing options...
MadTechie Posted October 13, 2008 Share Posted October 13, 2008 quick code <?php $URLQuery = (!empty($_SERVER['QUERY_STRING']))?$_SERVER['QUERY_STRING']:"?"; echo "<a href=\"$URLQuery\">THIS LINK</a>"; //if not empty and is set to DESC then use DESC else use ASC $SORT = (!empty($_GET['sort']) && $_GET['sort'] == "DESC")?"DESC":"ASC"; $SQL = "SELECT * FROM TABLE ORDER BY $SORT"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664032 Share on other sites More sharing options...
ngreenwood6 Posted October 13, 2008 Author Share Posted October 13, 2008 I get how to do it. But my question was if I dont know what is going to be in the url already how do I add something to the url? Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664036 Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 His question is how does he know if it's: www.mysite.com/index?var1=abc OR www.mysite.com/index?var1=abc&var2=def So basically how does he know when to add ?var= or &var=. Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664043 Share on other sites More sharing options...
MadTechie Posted October 13, 2008 Share Posted October 13, 2008 This line of code GETs the URL $URLQuery = (!empty($_SERVER['QUERY_STRING']))?$_SERVER['QUERY_STRING']:"?"; to get the values from www.mysite.com/index?var1=abc&var2=def you use $_GET ie <?php echo "var1=".$_GET['var1']; //or if($_GET['var2']=='def') { echo "var2 = def"; }else{ echo "var2 is not = def"; } ?> or have a missed the question again ? His question is how does he know if it's: www.mysite.com/index?var1=abc OR www.mysite.com/index?var1=abc&var2=def So basically how does he know when to add ?var= or &var=. Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664066 Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 or have a missed the question again ? Yes, you have. The question is how to create the URL. Cause it may be 'index.php' and you would use a '?'. Or it may have 1 or more vars in the URL 'index.php?var1=abc' and you would need to use the '&'. The question is how to determine these situations...? Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664067 Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 TOPIC SOLVED, nevermind MadTechie, I guess you got it. Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664068 Share on other sites More sharing options...
ngreenwood6 Posted October 13, 2008 Author Share Posted October 13, 2008 No he didnt get it but I figured i would start a new topic because it was not the same subject as the original. Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664072 Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 Ah OK, I just saw that. Quote Link to comment https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664074 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.