jaymc Posted December 16, 2008 Share Posted December 16, 2008 I have a member database, and with that I have a members online list, heres the problem If a member is over 18, I want to display members over 16 first, then when there are no more over 16's, show anyone else (14, 15 year olds etc) So in other words there may be 23 pages of over 16's, then the 24th page will show 14 and 15 year olds How can I make this into a query, as obvious "select * from members where age >= 16" will not show any under 16s on page 24.. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/137172-age-based-query/ Share on other sites More sharing options...
waterssaz Posted December 16, 2008 Share Posted December 16, 2008 Yes but using the above will display all members who match that criteria. You can print those out to the screen. Then you can run another query for the 14-15 year olds and simply append that onto the end Quote Link to comment https://forums.phpfreaks.com/topic/137172-age-based-query/#findComment-716559 Share on other sites More sharing options...
jaymc Posted December 16, 2008 Author Share Posted December 16, 2008 I am not displaying them in 1 big list, there will be 20 per page and 50 pages, thats why its a bit tricky Any more ideas? Quote Link to comment https://forums.phpfreaks.com/topic/137172-age-based-query/#findComment-716571 Share on other sites More sharing options...
waterssaz Posted December 16, 2008 Share Posted December 16, 2008 could you not just do a select on age descending or something? Quote Link to comment https://forums.phpfreaks.com/topic/137172-age-based-query/#findComment-716584 Share on other sites More sharing options...
jaymc Posted December 16, 2008 Author Share Posted December 16, 2008 No, as I dont want it to show oldest first, needs to be pretty random rather than display 30 year olds on the first 4 pages when its an 18 year old viewing Quote Link to comment https://forums.phpfreaks.com/topic/137172-age-based-query/#findComment-716596 Share on other sites More sharing options...
waterssaz Posted December 16, 2008 Share Posted December 16, 2008 ok no probs, obviously I'm not fully understanding what you are trying to do :-) Quote Link to comment https://forums.phpfreaks.com/topic/137172-age-based-query/#findComment-716603 Share on other sites More sharing options...
jaymc Posted December 16, 2008 Author Share Posted December 16, 2008 lets say I have these ages 14,15,15,16,17,20,23,25,25,26,29,30 I want to display them something like this 23,17,30,16,26,25,25,20,15,14,15 In other words, any age under 16 can never come before an age 16 or over I cant do a subquery because im not displaying all the results in one big list, they will be paginated Quote Link to comment https://forums.phpfreaks.com/topic/137172-age-based-query/#findComment-716616 Share on other sites More sharing options...
fenway Posted December 16, 2008 Share Posted December 16, 2008 You just need to add another binary expression to check for the 18 restriction and all this to the order by. Quote Link to comment https://forums.phpfreaks.com/topic/137172-age-based-query/#findComment-717150 Share on other sites More sharing options...
jaymc Posted December 17, 2008 Author Share Posted December 17, 2008 Can you give an example of what you mean fenway? Quote Link to comment https://forums.phpfreaks.com/topic/137172-age-based-query/#findComment-717636 Share on other sites More sharing options...
fenway Posted December 17, 2008 Share Posted December 17, 2008 ORDER BY IF( age >= 16, 0, 1 ) ASC Quote Link to comment https://forums.phpfreaks.com/topic/137172-age-based-query/#findComment-718063 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.