Printing selective elements of an array

From: Date: Mon, 21 Jan 2002 14:38:00 +0000
Subject: Printing selective elements of an array
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2554@lists.php.net to get a copy of this message
Hi. I'm having a problem looping through an array and only printing out certain elements. My existing php code is as follows: for($i = 0; $i < count($search_artist); $i++) { if($search_artist[$i][artist_name] == $search_artist[$i-1][artist_name]) { echo "<a href=\"/product/catalogue_no/".$search_artist[$i][catalogue_no]."\">".$searc h_artist[$i][product_title]."</A><BR> "; } else { echo "<BR><BR><B>".$search_artist[$i][artist_name]."</B><BR> "; echo "<a href=\"/product/catalogue_no/".$search_artist[$i][catalogue_no]."\">".$searc h_artist[$i][product_title]."</A><BR> "; } } My non-working smarty code is: {section name=list loop=$search_artist} {if $search_artist[list].artist_name == $search_artist[list-1].artist_name} {* I have tried using index & index_prev to no avail. I have also tried creating an array and offseting it by one to use instead of [list] *} <a href="/product/catalogue_no/{$search_artist[list-1].catalogue_no}">{$search_ artist[list].product_title}</A><BR> {else} <BR><BR><B> {$search_artist[list].artist_name}</B><BR> <a href="/product/catalogue_no/$search_artist[list].catalogue_no">{$search_arti st[list].product_title}</A><BR> {/if} {/section} Is there a way to offset the section name by one? Any help would be appreciated. Regards Neil

« previous php.smarty.general (#2554) next »