johnwayne77 Posted February 21, 2009 Share Posted February 21, 2009 i have a classifieds system which i recently launched it. i get each classified in the system by ---while($row = mysql_fetch_array($result))--- which loops until it reaches the end of the table i really need to place ads in the classified page, let's say after 5 classifieds i need a banner placed how can i halt loop to insert code then continue loop any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/146238-solved-whilerow-mysql_fetch_arrayresult/ Share on other sites More sharing options...
Cal Posted February 21, 2009 Share Posted February 21, 2009 $i = 1; while($row = mysql_fetch_array($result)){ $i++ //echo table if($i == 5){ //echo banner $i = 1; } } Quote Link to comment https://forums.phpfreaks.com/topic/146238-solved-whilerow-mysql_fetch_arrayresult/#findComment-767749 Share on other sites More sharing options...
Philip Posted February 21, 2009 Share Posted February 21, 2009 Or, similarly: <?php $i=1; while($row = mysql_fetch_array($result)) { if(!($i%5)) echo '*banner '; echo $i,' result<br />'; ++$i; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146238-solved-whilerow-mysql_fetch_arrayresult/#findComment-767751 Share on other sites More sharing options...
johnwayne77 Posted February 21, 2009 Author Share Posted February 21, 2009 great... i'm not sure how to use the increment in the while because i have a smarty template. i tried: {php} $i = 1; {/php} {foreach item=ad from=$ads} {php} $i++ {/php} <tr class="{cycle values=",alt"}"> <td class="pointer"><a href="{$ad.LINK}" title="{$ad.TITLE|escape}"> {if $ad.SPECIAL}{/if}<b>{$ad.TITLE}</b></a> (<span class="pretrosu">{$ad.PRET}</span>) <br /> {$ad.DESCRIPTION|truncate:150:"...":true} - <a href="{$ad.LINK}" title="{$ad.TITLE|escape}">detalii...</a>{if $ad.SPECIAL}{/if}</a><br /></td> <td><div align="center">{$ad.REGDATE}<br /> {$ad.IMAGEYESNO}</div></td> </tr> {if $i == 5} <b>hi</b> {php} $i = 1; {/php} {/if} but no luck.. any advices? Quote Link to comment https://forums.phpfreaks.com/topic/146238-solved-whilerow-mysql_fetch_arrayresult/#findComment-767761 Share on other sites More sharing options...
johnwayne77 Posted February 21, 2009 Author Share Posted February 21, 2009 great, {cycle} from smarty did all the job Quote Link to comment https://forums.phpfreaks.com/topic/146238-solved-whilerow-mysql_fetch_arrayresult/#findComment-768064 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.