i have this question :
i have $number_of_monthes = number of months with value =("1","3","6","12")
i have $number_of_pages = how many page is active on account with value=("1","3","7")
i have $marketing_level = how many ads can the user add into account with value=("25","100","300","500")
if($data['marketing_level'] == 100){
if($data['number_of_monthes '] == 1)
$marketing_cost = ( 50 * $number_of_monthes );
if($data['number_of_monthes '] == 3)
$marketing_cost = ( 50 * $number_of_monthes * $number_of_pages * 0.85 );
if($data['number_of_monthes '] == 6)
$marketing_cost = ( 50 * $number_of_monthes * $number_of_pages * 0.70 );
if($data['number_of_monthes '] == 12)
$marketing_cost = ( 50 * $number_of_monthes * $number_of_pages * 0.55 );
as you can see, if the user bought the 3 months package, then he will got a sale (15%)
and if he bought the 6 months package, then he will got a 30% sale
so how to also add the ability’s to got more sale when the number of pages get higher ?
i mean i want also like this :
if the number of months=3 then sale 15% and if the number of pages =3 then the sale will become 20%
if the number of months=3 then sale 15% and if the number of pages =7 then the sale will become 30%
if the number of months=6 then sale 30% and if the number of pages =3 then the sale will become 40%
if the number of months=6 then sale 30% and if the number of pages =6 then the sale will become 45%
and so on
thanks for your help in advanced
i searched a lot about it, but unfortunately found nothing
2
Answers
I suppose you know the percentage of rebate for each Month option and also for each Page number.
If so, you can do something like this to calculate the rebate coefficient:
After that you’ll multiply your base price by the value retuned from the function.
Examples:
These kind of problems you can solve with a matrix (perhaps not the right word), think of it as a table, but in more than two dimensions:
Each cell now contains the (calculated/intended) value (currently blank). That are 12 "boxes" to fill.
Now you add another dimension, let’s think you turn it side-wards and it has some little depth and look on it from the side, and then extend (left to right) for the next category, e.g. marketing level, just this time it needs one row of values for each cell, and here in the reduced schema it only shows one, as we look from only one side:
This are another 12 fields, but of all the stacks only 12 boxes visible but if we look up again, there are another three columns that are not visible, so there are 36 more boxes or in total 48: four times the twelve boxes of the first two dimensions for the third dimension that has four values.
In PHP that can be created with a multi dimensional array.
Let’s say the first dimension is Pages:
And the second dimension is Months:
And the third dimension is Marketing Level (what a dull exmaple btw.):
Now if you have all levels complete, here we stop at three, assign the value of each:
Then you can always look it up by the integer number in the keys. This allows you to have a different factor / calculation per "box"/field.
Or if the calculation is extremely expensive, to calculate it once and store it in this form. It then can be quickly looked up in the "table".