If you want more of my pastes visit:  https://randompaste.000webhostapp.com/index.html
--------------------------------------------------------------------------------------
view my last post at:  https://bitbin.it/gWG48q34/
--------------------------------------------------------------------------------------

<?php
/* Alle Sub Rubrieken*/
$query = mysql_query("SELECT * FROM tbl_sub_rubriek WHERE rubrieken_id='".$urls['cat']."' ORDER BY titel ASC");  
$array = array();  

while (($list = mysql_fetch_assoc($query)) != null) {  
    $array[] = array('id'    => $list['id']   ,  
                     'title' => $list['titel'],  
                     'scode' => $list['scode']  
        );  
}  


/* Alle advertenties */
	$query_ad = mysql_query("SELECT * FROM tbl_advertenties WHERE sub_rubriek_id='".$array[$j]['id']."' ORDER BY titel ASC");  
	$array_ad = array();  

	while (($list_ad = mysql_fetch_assoc($query_ad)) != null) {  
    $array_ad[] = array('id'    => $list_ad['id']   ,  
                     'title' => $list_ad['titel'],  
                     'scode' => $list_ad['scode']  
        );  
	}  

	$titel_advertentie = $array[$j]['titel'];




print '<table border="0" cellspacing="5" cellpadding="0">';  

for ($i = 0, $size = count($array); $i < $size; $i += 2) {  
    $scode = array();  

    print '<tr>';  
    for ($j = $i, $count = $i + 2; $j < $count; $j++) { 
        if (!isset($array[$j])) { 
            break; 
        } 
        $scode[$array[$j]['id']] = $array[$j]['scode'];  
		
		$titel_rubriek = $array[$j]['title'];
	
		printf('<td width="300" height="25" class="titel_rubrieken" valign="middle">- '.$titel_rubriek.'</td>', $array[$j]['id'], $array[$j]['title']) or die (mysql_error());
    }  

    print '</tr><tr>'; 
	 foreach ($scode as $id => $item) {  
   
	$titel_advertentie = $array_ad[$j]['titel'];
	
	//printf('<td width="300" height="25" class="titel_rubrieken" valign="middle">- '.$titel_advertentie.'</td>', $array[$j]['id'], $array[$j]['title']) or die (mysql_error());
	printf('<td width="300" height="100" valign="top" class="bg_rubrieken">'.$titel_advertentie.'</td>', $id, $item); 
	 }
	 
    print '</tr>';  
}  
print '</table>';  
?>