insert html between mysql records

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pertrai1
Forum Newbie
Posts: 2
Joined: Thu Apr 15, 2010 10:14 am

insert html between mysql records

Post by pertrai1 »

Hi, I am wondering if it is possible to add code after x amount of records in my while loop from mysql. I want to be able to insert a div that clears floats after 3 records. So for example:

Code: Select all

<?php $query_classifieds = mysql_query("SELECT id, categoryName, permalink, is_active FROM classified_categories WHERE is_active = '1' && parentId = '$parentId' ORDER BY categoryName ASC");
              while ($row_classcat = mysql_fetch_array($query_classifieds)) { ?>
                <div class="classified-categoryBox">
                	<h2 class="subcategory"><a href="./<?php echo $row_parent['permalink']; ?>/<?php echo $row_classcat['permalink']; ?>.html" title="<?php echo $row_classcat['categoryName']; ?> classified ads"><?php echo $row_classcat['categoryName']; ?></a></h2>
                	<?php 
                	$id = $row_classcat['id'];
                	$catcount = mysql_query("SELECT id FROM classifieds WHERE categoryid = '$id'");
                	$totalads = mysql_num_rows($catcount);
                	?>
                	<p>Current number of ads: <?php echo $totalads; ?></p>
                </div><!--end classified ad box-->
   <?php } ?>
So each of my div's are floating to the left. Each record is stored in a div. I would like to insert a div that clears the floats for a new line of div's. I hope this makes sense. COuld someone show me how this could be done, if it can be done. Thank you

Rob
Last edited by Benjamin on Thu Apr 15, 2010 11:55 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: insert html between mysql records

Post by Weiry »

Posting Code in the Forums
Read It.
pertrai1 wrote:after 3 records

Code: Select all

$i=0;
while(){
    if($i%3){ print "new div"; } // ($i % 3) every 3 records.
    $i++;
}
pertrai1
Forum Newbie
Posts: 2
Joined: Thu Apr 15, 2010 10:14 am

Re: insert html between mysql records

Post by pertrai1 »

Sorry I did not read the posting guidelines first. I won't do this again.
Post Reply