Lambneck Posted July 31, 2009 Share Posted July 31, 2009 hello, The following code displays a list of blog entries. Im trying to set up the code so that it displays an ad after the third and ninth output on the blog. Can anyone point me in the right direction with this? what im working with: <?php require_once('load.php'); if (!mysql_connect($db_host, $db_user, $db_pwd)) die('<strong style="color:maroon">Sorry, database undergoing maintenance. Please try again later.</strong>'); if (!mysql_select_db($database)) die("Can't select database"); $result = mysql_query("SELECT * FROM $table WHERE submission_date BETWEEN UNIX_TIMESTAMP(DATE_SUB( CURDATE( ) ,INTERVAL 5 DAY )) and UNIX_TIMESTAMP( ) ORDER BY submission_id DESC")or die(mysql_error()); while($row = mysql_fetch_array($result)) { $subject = $row['col_2']; echo '<div class="posts">'; echo '<h2>'; echo '<a href="blog.php?id='.$row['submission_id'].'" class="link">'.stripslashes(htmlspecialchars($row['col_4'])).'</a>'; echo '</h2>'; echo '--<em>'; echo '<a href="user.php?id='.urlencode($subject).'" title="recent posts by '.$row['col_2'].'">'.stripslashes(htmlspecialchars($row['col_2'])).'</a>'; echo '</em> '; echo date("M dS, Y", $row['submission_date']); echo '<p>'; echo stripslashes(substr($row[col_5],0,350)).' <strong><a href="blog.php?id='.$row['submission_id'].'">Read more >></a></strong>'; echo '</p>'; echo "</div>"; } mysql_free_result($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/168247-solved-counter-issue-3rd-and-9th-display/ Share on other sites More sharing options...
phpSensei Posted July 31, 2009 Share Posted July 31, 2009 <?php require_once('load.php'); $counter = 0; if (!mysql_connect($db_host, $db_user, $db_pwd)) die('<strong style="color:maroon">Sorry, database undergoing maintenance. Please try again later.</strong>'); if (!mysql_select_db($database)) die("Can't select database"); $result = mysql_query("SELECT * FROM $table WHERE submission_date BETWEEN UNIX_TIMESTAMP(DATE_SUB( CURDATE( ) ,INTERVAL 5 DAY )) and UNIX_TIMESTAMP( ) ORDER BY submission_id DESC")or die(mysql_error()); while($row = mysql_fetch_array($result)){ $counter++; if(($couter == 3)||($counter==9)){ //ad }else{ //post } } mysql_free_result($result); ?> ?> its manually adding at whats posts it should put an AD.. Quote Link to comment https://forums.phpfreaks.com/topic/168247-solved-counter-issue-3rd-and-9th-display/#findComment-887425 Share on other sites More sharing options...
Lambneck Posted July 31, 2009 Author Share Posted July 31, 2009 ok great! i tried it and the ad comes up after the 9th output but not the 3rd. so i tried replacing or || with and && but that didnt work at all. any idea how to get the ads to pop out after both the 3rd and 9th output? Quote Link to comment https://forums.phpfreaks.com/topic/168247-solved-counter-issue-3rd-and-9th-display/#findComment-887450 Share on other sites More sharing options...
Lambneck Posted July 31, 2009 Author Share Posted July 31, 2009 oh i see theres a typo! thanks! works now! Quote Link to comment https://forums.phpfreaks.com/topic/168247-solved-counter-issue-3rd-and-9th-display/#findComment-887451 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.