![]() |
Function for sorting array
Hello,
I am trying to implement a table to show product variants so a customer doesn't have to click the dropdown to see the price. I have the table functioning, however, I would like it to be sorted by price (lowest first). This is how it is appearing now: http://mermaids-natural-skin-care.com/images/Sizes.gif Does anybody know how I can put a sort (lowest price 1st) into the following code: {***BEGIN Mod to add Variant Table***} {if $variants ne ""} <tr id="product_weight_box"> <td width="30%"> </td> <td nowrap="nowrap"> </td> </tr> <table width="100%" cellpadding="0" cellspacing="0"><tr><td colspan="4"><b><font class="ProductDetailsTitle">{$lng.lbl_AvailableSiz es}</font></b></td></tr> <tr><td class="Line" height="1" colspan="4"><img src="{$ImagesDir}/spacer.gif" class="Spc" alt="" /><br></td></tr> <tr><td colspan="4"> </td></tr> <tr> {foreach name=variants from=$variants item=tempVar} <td colspan="4"> {foreach from=$tempVar.options item=tempOpt} <tr> <td width="45%"> {$tempOpt.option_name} </td> <td align="left" width="5%"> {include file="currency.tpl"} </td> <td align="right" width="10%"> {$tempVar.price} </td> <td align="right" > </td> </tr> {/foreach} </td> {if $smarty.foreach.variants.iteration is div by 3} </tr> <tr> {elseif not $smarty.foreach.variants.last} <td width="30%"></td> {/if} {/foreach} </tr> </table> {/if} {***END Mod to Add Variant Table***} Thanks so much! :-) |
Re: Function for sorting array
have a look at http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1079
or you can sort it in php using something like 'usort' and pass that array to smarty |
Re: Function for sorting array
Thanks! I actually saw the thread on the other forum but didn't read far enough. I'm going to give it a try (I'm really new to php) so I may be back with more questions!:?
|
Re: Function for sorting array
I'm having a bit of trouble with this. Can anybody tell me which php file I would put the sort function in? Also, what would be the smarty syntax to call the function in which an array is being passed to the function, sorted, and returned? Thanks so much!
|
All times are GMT -8. The time now is 05:25 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.