Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert HTML on specific count

Status
Not open for further replies.

jfilan

Technical User
Aug 2, 2007
4
US
I have the following template that repeats itself in the results:

<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>product</td>
</tr>

</table>

And right now I am showing 10 per page w/ a pager. I want to be able to count the repeated template and insert a banner ad after the template repeats 5 times. So it would be like:

template
template
template
template
template
template
BANNER
template
template
template
template
template

Do I give the template an ID and do some type of counting? And if ID COUNT equals 5 then post banner ad? I just need to get a little jump start in the right direction.

I would like to accomplish it this way:

<table width="300" border="0" cellspacing="0" cellpadding="0" id="searchtemplate">
<tr>
<td>product</td>
</tr>

</table>
<?php include("count.php"); ?>

Can someone show me how to do this? Or post an example script that I could modify?
 
assuming you are outputting the rows from a database

Code:
$counter = 1;
while ($row = mysql_fetch_assoc($result)){
 //output row for product
 if ($counter  == 5){
  showBanner();
  $counter = 1;
 } else {
  $counter ++;
 }
}

function showBanner(){
//insert the banner row
}
 
thanks jpadie. do i save that as my include? yes, the results are coming from a mysql database.
 
no - just use this as your main rendering code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top