Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can add a counter inside your loop. For example:</p> <pre><code>$counter = 0; // before the loop starts </code></pre> <p>and inside the loop:</p> <pre><code>$counter++; if ($counter == 4){ $blogList .= "/* your AD here*/" ; $counter = 0; } </code></pre> <p>Hope this helps<br> (and remember your mysql_query is deprecated, read more about it <strong><a href="http://www.php.net/manual/en/function.mysql-query.php" rel="nofollow">here</a></strong>)</p> <p><strong>EDIT:</strong> </p> <pre><code> &lt;?php // Check to see the URL variable is set and that it exists in the database // Connect to the MySQL database error_reporting(E_ALL ^ E_NOTICE); //this is for debugging, remove if you dont need anymore ini_set("display_errors", 1); //this is for debugging, remove if you dont need anymore $blogList = ''; include "connect.php"; $sql = mysql_query("SELECT * FROM articles WHERE id &gt;8 ORDER BY id DESC LIMIT 6"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount &gt; 0) { // get all the product details $counter = 0; while($row = mysql_fetch_array($productCount)){ $id = $row["id"]; $article_title = $row["article_title"]; $category = $row["category"]; $readmore = $row["readmore"]; $author = $row["author"]; $date_added = $row["date_added"]; $content = $row["content"]; $short = substr(strip_tags($content), 0, 750); $shortTitle = substr(strip_tags($article_title), 0, 45); $counter++; if ($counter == 4){ $blogList .= '&lt;div class="blogSnippetTitle"&gt;&lt;a href="http://www.#.com/better-trader.php?id='.$id.'"&gt;&lt;h2&gt;'.$article_title.'&lt;/h2&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogSnippet"&gt;&lt;div class="blogImage"&gt;&lt;img src="http://www.#.com/trading_images/'.$id.'.jpg" height="142px" width="200px" alt="'.$category.' '.$shortTitle.'" /&gt;&lt;/div&gt;&lt;div class="blogSnippetPrev"&gt;&lt;div class="citation"&gt;By &lt;span style="color:#006699;"&gt;'.$author.'&lt;/span&gt; on &lt;span style="color:#99aacc;"&gt;'.$date_added.'&lt;/span&gt; in &lt;span style="color:#006699;"&gt;'.$category.'&lt;/span&gt;&lt;/div&gt; &lt;div class="snippet"&gt;'.$short.'...&lt;br /&gt;&lt;/div&gt; &lt;div class="readMoreButton"&gt;&lt;br /&gt;&lt;a href="http://www.#.com/better-trader.php?id='.$id.'"&gt;&lt;img src="http://www.#.com/images/read_more.png" alt="read more graphic" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;'; $counter = 0;} $blogList .= ' &lt;div class="blogSnippetTitle"&gt;&lt;a href="http://www.#.com/better-trader.php?id='.$id.'"&gt;&lt;h2&gt;'.$article_title.'&lt;/h2&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogSnippet"&gt;&lt;div class="blogImage"&gt;&lt;img src="http://www.#.com/trading_images/'.$id.'.jpg" height="142px" width="200px" alt="'.$category.' '.$shortTitle.'" /&gt;&lt;/div&gt;&lt;div class="blogSnippetPrev"&gt;&lt;div class="citation"&gt;By &lt;span style="color:#006699;"&gt;'.$author.'&lt;/span&gt; on &lt;span style="color:#99aacc;"&gt;'.$date_added.'&lt;/span&gt; in &lt;span style="color:#006699;"&gt;'.$category.'&lt;/span&gt;&lt;/div&gt; &lt;div class="snippet"&gt;'.$short.'...&lt;br /&gt;&lt;/div&gt; &lt;div class="readMoreButton"&gt;&lt;br /&gt;&lt;a href="http://www.#.com/better-trader.php?id='.$id.'"&gt;&lt;img src="http://www.#.com/images/read_more.png" alt="read more graphic" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; '; } } else { $blogList = "You have no products listed in your store yet"; } mysql_close(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload