Andrew R Posted April 12, 2009 Share Posted April 12, 2009 Hi I have the following SQL Query... SELECT * FROM sites where type = 'bar' ORDER by name asc Inside my table I have another column called type_break which contains data such as traditional, trendy, club etc. How would I sort each result by column name using one query . For example Traditional <lists all traditional> Trendy <lists all trendy> Club <lists all clubs> Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/153765-group-results/ Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 You mean, like this? SELECT * FROM sites where type = 'bar' ORDER by type_break, name asc Quote Link to comment https://forums.phpfreaks.com/topic/153765-group-results/#findComment-808135 Share on other sites More sharing options...
Andrew R Posted April 12, 2009 Author Share Posted April 12, 2009 I need the results to be sorted into their appropriate column for example. <h1>Tradional<h1> echo results here <h1>Clubs</h1> echo results here Quote Link to comment https://forums.phpfreaks.com/topic/153765-group-results/#findComment-808146 Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 The query i posted first sorts by your type_break, then by names within each type_break. So it's down to formatting the results. So in your loop that fetches the results, you would have a condition that checks if type_break changes. If it changes, start a new header. Quote Link to comment https://forums.phpfreaks.com/topic/153765-group-results/#findComment-808150 Share on other sites More sharing options...
Andrew R Posted April 12, 2009 Author Share Posted April 12, 2009 Thanks very much. Would anyone have an example of that? Quote Link to comment https://forums.phpfreaks.com/topic/153765-group-results/#findComment-808160 Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 there are a million tutorials out there showing how to format things by group. Make an effort to look for them or try on your own. We're here to help you through your coding endeavors, not write stuff for you. Quote Link to comment https://forums.phpfreaks.com/topic/153765-group-results/#findComment-808173 Share on other sites More sharing options...
Andrew R Posted April 12, 2009 Author Share Posted April 12, 2009 Been looking for additional information on this, can't seem to find anything, must be searching for the wrong thing. Anyway thanks a million Quote Link to comment https://forums.phpfreaks.com/topic/153765-group-results/#findComment-808186 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.