View Single Post
  #20  
Old 11-26-2002, 08:24 PM
 
derrick92130 derrick92130 is offline
 

Advanced Member
  
Join Date: Nov 2002
Location: San Diego, California USA
Posts: 68
 

Default more Smarty fun

AJ,

I did look through your posting again (actually read it closely this time) and think I see what the problem is. In my example, I was using the product (not products) table and therefore could do a simple lookup in the php code and pass the variable onto the tpl. In your case, you have an entire array of products. In your sample code (from the Forum), you are trying to do a select to populate the $unit_text array that is trying to match "code" to an entire array, not a single element. That is what is causing the access error.

Just load the entire "units" table into the "$unit_text" array in the products.php program.
Code:
$unit_text = func_query("SELECT unit, code FROM units");
Then in the products.tpl file you can get to the "code" a couple of ways. The brute force way would be to nest a {section} loop around the $unit_text array and then just test for a match:

Code:
{section name=unittext loop=$unit_text} {if $unit_text[unittext].unit == $products[product].unit} Unit of Issue: {$unit_text[unittext].code} {/if} {/section}
A more elegant way would be to use the $products[product].unit to reference the index of the php array. I doubt have the syntax correct, but would be very clean. I'd make the {section} work first to lower your frustration level, then try this:

Code:
{$unit_text['$products[product].unit'].code}


Give it a try! If it still doesn't work, send me an email and I should be able to get my test site back on 3.2.2 tomorrow.

Hope this helps.
__________________
-Derrick
FreeRangeMinds, LLC
Reply With Quote