Page 1 of 1

Select Highest Postage Band?

Posted: Fri Dec 03, 2010 3:44 am
by djlex1928
Hi,

I am currently working on a shopping cart. Here is an example of my shopping cart database:

id // part // qty // price // band
1 // 659 // 2 // 5.68 // A
1 // 814 // 1 // 96.32 // C
2 // 546 // 1 // 10.63 // B

The session number is the id column and the band is the delivery cost. Lets say the customer currently on my website has the session id 1.

I need to loop through my database (This I do know how to do lol :P) and I need to be able to return the highest letter in the band column. I'll explain why so you can understand my objective.

A customer adds part '659' to their cart and the delivery band A is shown. (Delivery band A is $1.99) Then they added part '814' which has a delivery band of C, my postage then should automatically rise to postage band C. ($4.99) Totally forgetting the first part, I just need to be able to return 1x the highest postage band.

I already know how I can achieve this however I'm pretty sure I'll be doing it wrong in a lengthy function that's not necessary. Would like your input on this one to see what options I have.


Thanks,
Alex

Re: Select Highest Postage Band?

Posted: Fri Dec 03, 2010 4:20 am
by curlybracket
Why no to do "ORDER BY band DESC LIMIT 1" in your SQL?

Re: Select Highest Postage Band?

Posted: Fri Dec 03, 2010 4:37 am
by djlex1928
Wow, now I feel like an idiot lol. I thought ORDERBY was numeric entries only.

For anyone reading with the same question, here's the sql query I used:

Code: Select all

SELECT * FROM `carts` WHERE id='1' ORDER BY band DESC LIMIT 1
Thanks a million,
Alex