Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/128207-solved-order-by/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664025
Share on other sites

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";
?>

Link to comment
https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664032
Share on other sites

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=.

Link to comment
https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664066
Share on other sites

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...?

Link to comment
https://forums.phpfreaks.com/topic/128207-solved-order-by/#findComment-664067
Share on other sites

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.