Page 1 of 1

FOREACH: multi dimensional

Posted: Wed Jul 09, 2003 5:53 pm
by AaronSmith
I want to take categories from the database and place them in an HTML table on the page, five columns across. Each main category has it’s “own” page, dynamically generated from another main index; thus, I can’t use any specific “category names” as I have no clue which categories might be on any given page.

How would I cut this up so that it will place a </TR><TR>after every five categories as to look symmetrical in design? From my searching of this forum and the PHP manual I believe what I am trying to do is called a multi dimensional array, but am not certain how to go about this.

Code: Select all

<?
    $topcat = new cat(0,"realestate");
	$topcat->ID = $class_category;
    $topcatlist = $topcat->subcats();
    foreach ( $topcatlist as $c )
    &#123;
		$co = get_cat($c);
	    $cs = $co->get_strings("US");
        echo "<a href='/realestate/listings/index.php?cat=$c' onFocus='if(this.blur)this.blur()'> &#123;$cs->cat_name&#125; </A>&nbsp;&nbsp;";
        $sclist = $co->subcats();
        foreach ( $sclist as $sc )
        &#123;
			$sco = get_cat($sc);
			$scs = $sco->get_strings("US");
			echo "<a href='/realestate/listings/index.php?cat=$sc' onFocus='if(this.blur)this.blur()'> &#123;$scs->cat_name&#125; </A></TD>";
        &#125;
    &#125;
?>
Any help is appreciated.

Posted: Wed Jul 09, 2003 9:09 pm
by Unifex
where is your current opening TD?

Posted: Wed Jul 09, 2003 11:07 pm
by AaronSmith
Here is the fix:

Code: Select all

<?
    $topcat = new cat(0,"realestate");
	$topcat->ID = $class_category;
    $topcatlist = $topcat->subcats();
	$count = 1;
    foreach ( $topcatlist as $c )
    &#123;
      $co = get_cat($c);
       $cs = $co->get_strings("US");
        echo "<TD valign=middle width=90 align=left><FONT FACE='arial' color='#000080' class='realestate-links2' style='font-size:8.5pt; mso-bidi-font-size:8.5pt;font-family:Arial'><B><a href='/realestate/listings/index.php?cat=$c' onFocus='if(this.blur)this.blur()'> &#123;$cs->cat_name&#125; </A></TD>";
        $sclist = $co->subcats();
        foreach ( $sclist as $sc )
        &#123;
         $sco = get_cat($sc);
         $scs = $sco->get_strings("US");
         echo "<a href='/realestate/listings/index.php?cat=$sc' onFocus='if(this.blur)this.blur()'> &#123;$scs->cat_name&#125; </A></TD>";
        &#125;
	if($count == 5)&#123;
	echo "</tr><tr>";
	$count = 1;
	&#125;
	else&#123;
	$count++;
	&#125;
    	&#125;
	echo "</tr>";
?>