Jump to content

Multiply Several Rows of Table A by Specific Rows From Table B


CFennell

Recommended Posts

Hello all,

 

Somewhat new to PHP.  Been able to get to this point without much help.  The code I'm currently working on is by far the most ambitious challenge I've faced.  It's also, kind of the key to my project.  Therefore, I figured I'd ask for some assistance to guide me before I head too far down the wrong path.  I have the concept worked out, just how to code it I'm really not sure where to start.

 

The overall goal is to multiply some values together so I figured this was the place to post.  If not, I appologize, please move appropriately. 

 

A quick overview of what I'm trying to accomplish.  (Sorry, no actual examples as this is still in the concept stage.)  I'll have the following 6 tables:

item1

id

stat1

stat2

stat3

 

item2

id

stat1

stat2

stat3

 

item3

id

stat1

stat2

stat3

 

 

order

id

group_id

item1_id

item2_id

item3_id

 

group_setup

group_id

stat1_mult

stat2_mult

stat3_mult

 

final_table

order_id

item1_id

item1_value

item2_id

item2_value

item3_id

item3_value

 

The items tables will store the current stats for each individual items with a unique id.  These will change periodically and the final table will need to be updated accordingly so users can view their current order totals.

 

The order table will have an item id from each item selected from each of the items tables.  An associated value which is the item's stat multiplied by the stat_mult associated with it in the group_setup table.  As well as the group id that the order belongs to. 

 

The group_setup table will contain the unique id of the group and the values of the multipliers that the item stats need to be multiplied by for that particular goup.

 

The final_table will have the three items id and an associated value which is the item's stat multiplied by the stat_mult associated with it in the group_setup table. 

 

On an administrative page, I need to build code that after updating the item stats, I can multiply the stat by the stat_mult and insert that value into the final table.  My problem lays with the variable values the different group's stat mult will have.  I can get it to work with a fixed value, but the variable values would really make the application a lot more marketable. 

 

I'm not quite sure where to begin.  If the row count was equal throughout the tables, I think I could work it out.  But the group_setup only having one row for multiple order rows is what's throwing me off.  If anyone has any suggestions as to how to proceed, I would greatly appreciate the advice.

 

Thank you in advance,

Craig

 

I think I'm making progress using multidimensional arrays and array_walk.  I'm going to leave this as unsolved for the moment.  Hopefully, tomorrow after a good nights sleep I'll make some good progress.  I'll post updates as I go.

 

Thank you,

Craig

Screw the sleep! :P  I was able figure it out.  I created a multidimensional array, then put that into an array_walk where in the function of the array_walk, I did an sql query on the group_setup to pull the multiplier information for each order dependent on what group it's in. 

 

Still need to pull everything together, but I was able to get a basic example to work properly. 

 

I think kind of taking a step back and putting (or trying to put) into words what I was trying to accomplish allowed me to really break down the logic step by step and use the tools I had to get the job done.

 

The finish product may not be the most efficient way, but it should work.

 

Craig

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.