Going loop the loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stebut05
Forum Commoner
Posts: 35
Joined: Wed Sep 21, 2005 9:29 am
Location: Liverpool, UK

Going loop the loop

Post by stebut05 »

Hi all,

Have a small problem, would really appreciate any help given as deadline is near!!
The site i have built is working fine, but client has asked for something extra (again!!). I have assigned category id's to each product.

real tree = category one
pot grown = category two
artificial = category three
pre-lit = category four
lights = category five

etc etc.

When a user is 'checking out' they select a delivery zone for shipping and based on the zone they select a delivery charge is assigned. This all works fine, but now the client wants to add a delivery charge for each item in shopping basket that has a category id of 1, 2, 3 or 4.

e.g

1 real tree + 1 light + 4 decorations == one delivery charge

1 real tree + 2 lights + 1 pre-lit tree + 2 decorations = two delivery charges

2 pot grown + 1 real + 1 pre-lit + 5 decorations + 2 lights == 4 delivery charges.


What i need is some sort of loop function i think?? That will loop through all the items in the basket and count the items that have a category id of 1, 2, 3, 4 and then mulitply items by delivery charge. However, i am unsure how to implement this function and would really, really, really appreciate your help. Thanks for all help, advice and suggestions given, thanks

Regards,

Steven
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

first you need to flesh out what the logic for the charge stepping is, as I don't see much logic in there... I'm guessing you have the item list stored in a database table, so using an aggregate function like MySQL's COUNT() with a GROUP BY on the category field will yield the resulting counts for each category.. then just apply your charging logic to the results.
stebut05
Forum Commoner
Posts: 35
Joined: Wed Sep 21, 2005 9:29 am
Location: Liverpool, UK

Post by stebut05 »

Thanks, i will apply that now. Thanks again for your help

Regards,

Steven
Post Reply