Jump to content

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/258868-order-by-question/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/258868-order-by-question/#findComment-1327058
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/258868-order-by-question/#findComment-1327071
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.