phpjayx Posted January 8, 2013 Share Posted January 8, 2013 I have one sort working correctly.... $sql_select = "select * from data where userid='" . $param['userid'] . "' order by timestamp asc"; But if I also have a number ($param['number2']), which I also want to be included in the sort, what is the best way to do this? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 8, 2013 Share Posted January 8, 2013 That doesn't make much sense. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 8, 2013 Share Posted January 8, 2013 Add it to the sort order..? As Jessica said: Your questions doesn't make much sense, as you've given us too little information on what you actually want to do and why. If I didn't guess correctly as to what your intent is, please provide us with more information, so that we might be able to help you. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 8, 2013 Share Posted January 8, 2013 But why would you add a number to a sort? MySQL will interpret it as sort by the nth column (afaik, not sure if it does that if you've named another column in your order). If you're trying to do that, just use the name of the column. Quote Link to comment Share on other sites More sharing options...
Barand Posted January 8, 2013 Share Posted January 8, 2013 But why would you add a number to a sort? MySQL will interpret it as sort by the nth column Haven't you answered that question yourself - because they want to sort on the nth column, maybe? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 8, 2013 Share Posted January 8, 2013 So you think someone who doesn't know to simply add the number after his existing sort, actually knows that MySQL allows you to use the column numbers and wants to sort on it? *shrug* Barand you have more faith in people than I do I guess. Quote Link to comment Share on other sites More sharing options...
phpjayx Posted January 9, 2013 Author Share Posted January 9, 2013 Well you are correct that I know just the basics of the capabilities of MySQL, still learning.... Basically for this sort. I have grade numbers for people, that is my (number2), then the timestamp which is a checkin time, I was hoping to group all of the people with the same grade numbers together, but as well sort in ascending order Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 9, 2013 Share Posted January 9, 2013 Then you'll need to sort it on grade number first, and timestamp second. If you follow the link I posted above, you'll see how to sort on multiple fields. That said, I'm still not quite sure where the $param['number2'] variable comes into play here. In the best case scenario it doesn't, and you just included it in your description out of your own confusion. The worst case scenario would mean that you need to normalize your database tables, if you have multiple fields to signify the grade numbers. So, please post a bit more detail on what that variable contains, how you currently use it, and the table structure for the table in question. Remember, use accurate examples that showcase exactly what have; The more accurate information you give us, the easier it'll be for us to help you. Quote Link to comment Share on other sites More sharing options...
phpjayx Posted January 10, 2013 Author Share Posted January 10, 2013 Ok, I found it in your link... Thanks for the help! I ended up with the following which gave me what I needed $sql_select = "select * from data where userid='" . $param['userid'] . "' order by number2, timestamp asc"; Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 10, 2013 Share Posted January 10, 2013 You're most welcome, glad I could help. Also, thanks for posting the solution you reached. I'm sure others will find it useful. PS: You might need to look up on output escaping, and input validation, for your query. Not sure where the $param array comes from, but you might be open for SQL injections there. Since you're including a user ID, I'm going to assume it's an integer value, which means that typecasting it to an int before adding it to the query should be sufficient. Quote Link to comment 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.