I have a 3 column design of divs, what I want to do is limit 4 records displayed per div. These are specific, named divs, so it can't just be duplicated in an "if" statement.
so div 1 would display the first 4 records, div 2 would have 5-8 and div 3 would have 9-12, if there are any more I will provide a link with 13+
essentially i want to limit the amount of records shown to 12, but split in fours amongst 3 specific divs holding content on my page.
I hope this makes sense, any help would be appreciated.
Splitting records across divs
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
It sounds like you want a fairly simple modification of Useful Posts #1.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Completely untested. Something like this:
Code: Select all
$divsPerColumn = 3;
$maxColumns = 4;
for ($i=0; $row = mysql_fetch_object($result); ++$i) {
if ($i > $divsPerColumn * $maxDivs) {
echo '<a href="foo">More...</a>';
break;
}
if ($i % $divsPerColumn == 0) {
echo '<div>';
}
echo $row->field;
if ($i % $divsPerColumn == $divsPerColumn -1) {
echo '</div>';
}
}feyd | Please use
So what I want to do is display only the first four in "left column", the next four in "middleColumn" and the next four in "rightColumn"
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I looked through this and while it shows how to split records across a table, it generates the table while it gets the data. what I am talking about is displaying into existing containers, not creating the 3 containers as it goes.
this may be a simple modification of the ideas you pointed out, but I am not seeing it. here is the code as I have it, which is just querying the DB and then displaying everything in the first column.Code: Select all
mysql_select_db($database_chinadirectflooring, $chinadirectflooring);
$query_rebond = "SELECT rebond_id, density, thickness, single_price, volume_price, product_thumb FROM rebond";
$rebond = mysql_query($query_rebond) or die(mysql_error());
$row_rebond = mysql_fetch_assoc($rebond);
$totalRows_rebond = mysql_num_rows($rebond);
...
<div id="leftColumn">
<?php do { ?>
<div id="hotProducts">
<div id="hotProductPix"><img src="<?php echo $row_rebond['product_thumb']; ?>" alt="<?php echo ucwords($row_rebond['density']); ?>"></div>
</div>
<?php } while ($totalRows_rebond = mysql_fetch_object($rebond)); ?>
</div>
<div id="middleColumn">
</div>
<div id="rightColumn">
</div>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
You could use an array to accumulate the values from the database into, then array_slice() or array_shift() the first four out, move to the next column and repeat, etc.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK