\n"; /* the database query to fetch the items */ $query = "SELECT * FROM news"; /* make 2 list to store html texts before we glue them togheter */ $news_items = array(); $news_item_groups = array(); /** fetch and make html of each database row **/ $resource = mysql_query($resource) OR die('query failed'); while($result = mysql_fetch_assoc($resource)) { /* design html for each row */ $news_html = "
"; $news_html .= "

{$result['title']}

"; $news_html .= "

{$result['content']}

"; $news_html .= "
"; /* store html in list */ $news_items[] = $news_html; } /* split items up in groups */ foreach(array_chunk($news_items, $item_group_size) as $news_items_group) { /* glue each item in a group togheter and store in the 2nd list */ $news_item_groups[] = implode($item_separator, $news_items_group); } /* glue each group togheter */ echo implode($item_group_separator, $news_item_groups);