here is the code:
{section name=k loop=$obj->mProduct.attributes}
{* Generate a new select tag? *}
{if $smarty.section.k.first ||
$obj->mProduct.attributes[k].attribute_name !==
$obj->mProduct.attributes[k.index_prev].attribute_name}
{$obj->mProduct.attributes[k].attribute_name}:
<select name="attr_{$obj->mProduct.attributes[k].attribute_name}">
{/if}
{* Generate a new option tag *}
<option value="{$obj->mProduct.attributes[k].attribute_value}">
{$obj->mProduct.attributes[k].attribute_value}
</option>
{* Close the select tag? *}
{if $smarty.section.k.last ||
$obj->mProduct.attributes[k].attribute_name !==
$obj->mProduct.attributes[k.index_next].attribute_name}
</select>
{/if}
{/section}
I keep getting more than two select statements.
PLEASE HELP...

I expect:
Color:<select name="attr_Color">
<option value="White">White</option>
<option value="Black">Black</option>
//....
</select>
Size:<select name="attr_Size">
<option value="XL">XL</option>
<option value="L">L</option>
//....
</select>
However, I am getting multiple select tags instead of just two:
Color: <select name="attr_Color">
<option value="White">White</option>
</select>
Color: <select name="attr_Color">
<option value="black">black</option>
</select>
//...
Size: <select name="attr_Size">
<option value="l">l</option>
</select>
Size: <select name="attr_Size">
<option value="XL">XL</option>
</select>
//...
I can solve this pretty well with PHP, however, Smarty 3 is proving stubborn. You guys should help me out here.
I might migrate to twigs for separating presentation tier from business logic.
First, move your tag outside of the smarty for loop. For example:
{* Generate a new select tag? *}
<select name="attr_{$obj->mProduct.attributes[k].attribute_name}">
{section name=k loop=$obj->mProduct.attributes}
{* Generate a new option tag *}
<option value="{$obj->mProduct.attributes[k].attribute_value}">
{$obj->mProduct.attributes[k].attribute_value}
</option>
{/section}
</select>
This will return all attributes into one select box. You'll still need to group by attribute name somehow. This a bit outside the scope of your question, but:
SQL Method
You'll need to perform a GROUP BY DISTINCT SQL query on your attribute name to find all relevant attribute types, then iterate over the values for each type.
PHP Method Continue querying the same way you are now, but preprocess your data on the backend before you render it in your smarty template:
$attributes = array()
[for each row in sql query]
if ($attributes[$row.name] == null) {
$attributes[$row.name] = array()
}
$array_push($attributes[$row.name], $row.value)
[/end for]
In the end you'll have a nested for loop that does something like this (pseudo code):
[For each attribute_name in names]
<select name="{attribute_name}">
[For each attribute]
<option value="{$obj->mProduct.attributes[k].attribute_value}">
{$obj->mProduct.attributes[k].attribute_value}
</option>
[/end for (attribute)]
</select>
[/end for (names)]
If needed, you could wrap the whole <select/> in an if statement to hide it if there are no attributes to choose from.