Reputation: 85
im trying to figure out how to create new DIV every 8 MySQL rows queried. I am integrating jPagination into my site and so I need to create a new DIV container every 8 rows it receives from the database. Any ideas?
Upvotes: 0
Views: 1054
Reputation: 1876
<?php
// previous code.....
$counter = 1;
echo '<div class="outercssclass">';
echo '<div class="innercssclass">';
// fetch mysql query data into $results....
// you can do validations with mysql_num_rows to check the number of rows the query returned
foreach($results as $result) {
$counter++;
if($counter % 8 == 0) {
echo '</div><div class="innercssclass">';
}
// other logic...
// rest of the code
}
echo '</div>'; // for closing the inner div
echo '</div>'; // for closing the outer wrapper div
// rest of the program logic...
Upvotes: 0
Reputation: 3161
i = 1
while( gettingRows )
{
doWhateverYouDoHere()
if ( i%8 === 0 )
print "div"
++i
// or put increment right into the if statement like ( if i++ % 8 === 0 )
}
Upvotes: 0
Reputation: 1221
you need this: %
not sure about how your code exactly goes, but in the loop of every row you make a count++ and then something like this which would be in C:
if(!count%8) {
print DIV eccc
}
just so you understand what this % does: it gives you the remainer of a division. For example, if your row is number 20, so count equals to 20 at that moment, 20%8 will equal 4. That is because if you divide 20/8 you will have 2.** something, then multiply 2*8 you get 16. Take 20-16 = 4. So 20%8 is 4. Only when the number in count++ is perfectly divisible by number 8 you will get 0 zero there. So your IF statement says: if there ia no remain dividing count by 8 then do this
maxim
Upvotes: 1