Ok, I have a program that I'm writing, and it pulls a bunch of data from a MySQL database, and displays it in order from oldest to newest. I use the ORDER BY mysql command to do this when I first pull the data. Now I want a link on the page that lets them put the data in order by the number of items ordered. Do I need to name an order variable, and have it start as "date,time" and then change it and re-call the current page? or is there a better way?if you want the user to change the order then yeah, you have to reload the page.
if($_GET['order']){
$order= = $_GET['order'];
} else {
$order = "date";
}
select * form table ORDER BY $order
this give the userthe ability to chagne the order.
did I understand that right?yeah, I can do it like that. I'm already using sessions, so I'll probab;y set it as a sessions variable, and do this:
if($_SESSION['order']){
$order= = $_SESSION['order'];
} else {
$order = "date,time";
}
$result = mysql_query("select * form table ORDER BY $order");
I was just wondering...since the data's already all been read, is there a was to simply re-sort the array that it is in. I know that when I used to do c++, and I was reading info in from a file, that I could have it sort it however I wanted before outputting it. I know that I have to re-load the page, but do I need to re-read the database. Or does it really make any difference. I was just trying to make it run faster.On second thought, can I make a link that will set a $_SESSION variable? If so, how? If not, I suppose I will just do it through the URI.Ok, I'm currently trying to send the info through the URI, but if I need to pass a comma, how can I do that? I need to pass order=num_units,date or I might have to pass something like order=date,time etc etc.yes you have to do it from a link and you have to re-query the db. once the page is loaded of course you can't change things unless you refresh or reload the page.
why send 2, do you really need the comma or the second parameter?
if so you can look into the ascii value of the comma ,
or just send it like that normally. date,timeThanks scoutt...I thought that it wasn't sending the comma right, but I found out it was an error elsewhere in my code. Also, fyi, the comma can be sent as %2C through the URL. I have to send 2 like that (date,time) because a lot of data will be dumped into the db by a lot of different people, and LOTS of the data will have the same date (the date an order was placed), so I need to sort by a timestamp also. Also, same with # of units ordered. I actally pass num_units,date,time for that one. Anyway, It's sorting now. I appreciate the help. Now I just have to get the input part to verify the data right. I still haven't found a good answer to my preg_match (<!-- m --><a class="postlink" href="http://www.htmlforums.com/showthread.php?s=&threadid=35738">http://www.htmlforums.com/showthread.ph ... adid=35738</a><!-- m -->) question.
if($_GET['order']){
$order= = $_GET['order'];
} else {
$order = "date";
}
select * form table ORDER BY $order
this give the userthe ability to chagne the order.
did I understand that right?yeah, I can do it like that. I'm already using sessions, so I'll probab;y set it as a sessions variable, and do this:
if($_SESSION['order']){
$order= = $_SESSION['order'];
} else {
$order = "date,time";
}
$result = mysql_query("select * form table ORDER BY $order");
I was just wondering...since the data's already all been read, is there a was to simply re-sort the array that it is in. I know that when I used to do c++, and I was reading info in from a file, that I could have it sort it however I wanted before outputting it. I know that I have to re-load the page, but do I need to re-read the database. Or does it really make any difference. I was just trying to make it run faster.On second thought, can I make a link that will set a $_SESSION variable? If so, how? If not, I suppose I will just do it through the URI.Ok, I'm currently trying to send the info through the URI, but if I need to pass a comma, how can I do that? I need to pass order=num_units,date or I might have to pass something like order=date,time etc etc.yes you have to do it from a link and you have to re-query the db. once the page is loaded of course you can't change things unless you refresh or reload the page.
why send 2, do you really need the comma or the second parameter?
if so you can look into the ascii value of the comma ,
or just send it like that normally. date,timeThanks scoutt...I thought that it wasn't sending the comma right, but I found out it was an error elsewhere in my code. Also, fyi, the comma can be sent as %2C through the URL. I have to send 2 like that (date,time) because a lot of data will be dumped into the db by a lot of different people, and LOTS of the data will have the same date (the date an order was placed), so I need to sort by a timestamp also. Also, same with # of units ordered. I actally pass num_units,date,time for that one. Anyway, It's sorting now. I appreciate the help. Now I just have to get the input part to verify the data right. I still haven't found a good answer to my preg_match (<!-- m --><a class="postlink" href="http://www.htmlforums.com/showthread.php?s=&threadid=35738">http://www.htmlforums.com/showthread.ph ... adid=35738</a><!-- m -->) question.