FOREACH: multi dimensional

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AaronSmith
Forum Commoner
Posts: 32
Joined: Fri Mar 28, 2003 3:14 pm

FOREACH: multi dimensional

Post 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.
Last edited by AaronSmith on Wed Jul 09, 2003 9:23 pm, edited 1 time in total.
User avatar
Unifex
Forum Newbie
Posts: 14
Joined: Mon Jul 07, 2003 12:29 am

Post by Unifex »

where is your current opening TD?
AaronSmith
Forum Commoner
Posts: 32
Joined: Fri Mar 28, 2003 3:14 pm

Post 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>";
?>
Post Reply