phppup Posted March 13, 2012 Share Posted March 13, 2012 I have a database of assorted. Each row contains defined QUANTITIES for each column item. Example: columns for shirt, tie, pants, socks. A row would indicate a purchase of 2 shirts, 1 tie, 0 pants, 3 socks for customer A. Followed by a row indicate a purchase of 1 shirts, 1 tie, 4 pants, 2 socks for customer B, etc. Now I want to sort EACH item, group them by quantity, and get an ordered list by quantity, that provides me with something like this: 1 shirt customer B 2 shirt customer C 3 shirt customer F 3 shirt customer H 4 shirt customer D, etc. I am using this code for my query: $query = "SELECT brisket, COUNT(brisket) FROM pass GROUP BY brisket ORDER BY brisket ASC"; but it is not organizing the info in a correlated manner. Help? Quote Link to comment https://forums.phpfreaks.com/topic/258868-order-by-question/ Share on other sites More sharing options...
phppup Posted March 13, 2012 Author Share Posted March 13, 2012 OKAY, just noticed a twist! Apparently I am getting the result I expected WITH a troubling EXCEPTION: the data is being IN ORDER from 0 thru 9, but 10 (which in this test sample is my LARGEST quantity) is being inserted between the ONE and 2 quantity. Not sure if this will occur with ALL teen values, as well as hundreds. The column is a SMALLINT field (not sure if that makes a difference)> Is there a ssolution for this situation? Quote Link to comment https://forums.phpfreaks.com/topic/258868-order-by-question/#findComment-1327058 Share on other sites More sharing options...
l0gic Posted March 14, 2012 Share Posted March 14, 2012 If you're only having up to 99 things then pad 1-9 with a leading zero. 01, 02 .... 09, 10, 11, etc.. If you're having up to say 999 then pad more. 001, 002 .... 099, 100, 101, etc That should fix it. There may be other ways aswell, but I'd just do ^ that. Quote Link to comment https://forums.phpfreaks.com/topic/258868-order-by-question/#findComment-1327071 Share on other sites More sharing options...
phppup Posted March 14, 2012 Author Share Posted March 14, 2012 How do I accomplish the task of PADDING? IS this a common occurence? Quote Link to comment https://forums.phpfreaks.com/topic/258868-order-by-question/#findComment-1327072 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.