Welcome Guest, Not a member yet? Register   Sign In
Problems with arrays
#1

[eluser]Perkin5[/eluser]
I have a database table with product information - one column is called price but instead of a number it has a letter, so it's actually a price category.

I have another database table with a column for price category (cat) and a column for value (val), so it ties down what each price cat means in numerical terms eg price cat A is $3.00.

So in the controller I fetch the product information in an array and I fetch the price cat information in another array and they are both passed to the view as $records and $price respectively.

What I now want to do is display the product information in a foreach loop, but instead of a price category, I want to replace it with the actual price. Although the necessary information is available, I've been unable to find a solution that works.

I thought something like:

Code:
foreach ($records as $item):
   foreach ($price as $code){
if($code->cat == $item->price){$actual_price = $code->val;}

...more code

endforeach;

would do but CI throws an error.

I have an uneasy feeling I'm setting about this the wrong way. Can anyone suggest how it might be done?


Messages In This Thread
Problems with arrays - by El Forum - 03-25-2012, 10:40 AM
Problems with arrays - by El Forum - 03-25-2012, 10:46 AM
Problems with arrays - by El Forum - 03-25-2012, 01:02 PM
Problems with arrays - by El Forum - 03-25-2012, 01:05 PM
Problems with arrays - by El Forum - 03-25-2012, 01:19 PM
Problems with arrays - by El Forum - 03-25-2012, 01:34 PM
Problems with arrays - by El Forum - 03-25-2012, 01:40 PM
Problems with arrays - by El Forum - 03-25-2012, 01:50 PM
Problems with arrays - by El Forum - 03-25-2012, 01:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB