jodancer Posted April 16, 2012 Share Posted April 16, 2012 Hi, I'm quite new to this and I'm trying to get this to line up in a table with 3 columns (unlimited rows) I have searched and tried but I'm not having any luck. Can any one help? Thank you <?php echo '<div class="resultados_sub_cat">'; foreach($this->subcats as $key => $subcat) { $subcat->link = JRoute::_('index.php?option=classcliff&view=list&catid='.$subcat->id."&Itemid=".$this->Itemid); if ($key != 0) echo ' - '; echo '<a href="'.$subcat->link.'">'.$subcat->name.'</a>'; } ?> Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted April 16, 2012 Share Posted April 16, 2012 untested, but should be close: <?php echo '<div class="resultados_sub_cat">'; $colCount = 0; echo "<table>"; foreach($this->subcats as $key => $subcat) { if($colCount == 3){ echo "</tr>"; $colCount = 0 } if($colCount == 0){echo "<tr><td>";} else {echo "<td>";} $subcat->link = JRoute::_('index.php?option=classcliff&view=list&catid='.$subcat->id."&Itemid=".$this->Itemid); if ($key != 0) echo ' - '; echo '<a href="'.$subcat->link.'">'.$subcat->name.'</a></td>'; $colCount = $colCount++; } echo "</table>"; Quote Link to comment Share on other sites More sharing options...
jodancer Posted April 16, 2012 Author Share Posted April 16, 2012 Thank you for the fast reply! It's giving and error and I can't find out why! I'll keep trying Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted April 16, 2012 Share Posted April 16, 2012 reivewed, I missed a ; <?php echo '<div class="resultados_sub_cat">'; $colCount = 0; echo "<table>"; foreach($this->subcats as $key => $subcat) { if($colCount == 3){ echo "</tr>"; $colCount = 0; } if($colCount == 0){ echo "<tr><td>"; } else { echo "<td>"; } $subcat->link = JRoute::_('index.php?option=classcliff&view=list&catid='.$subcat->id."&Itemid=".$this->Itemid); if ($key != 0){ echo ' - '; echo '<a href="'.$subcat->link.'">'.$subcat->name.'</a></td>'; $colCount = $colCount++; } } echo "</table>"; Quote Link to comment Share on other sites More sharing options...
jodancer Posted April 16, 2012 Author Share Posted April 16, 2012 Thanks! No error now but I only have one column ? Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted April 16, 2012 Share Posted April 16, 2012 try moving this: $colCount = $colCount++; down a line so it is after that } which is directly under it just now Quote Link to comment Share on other sites More sharing options...
jodancer Posted April 16, 2012 Author Share Posted April 16, 2012 No luck unfortunately Quote Link to comment Share on other sites More sharing options...
jodancer Posted April 17, 2012 Author Share Posted April 17, 2012 Many hours later and I still can't get it into 3 columns, just one long column :'( Can any of you experts help? Thanks Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 17, 2012 Share Posted April 17, 2012 Posting your current code would help. Edit: BTW - you need logic after the end of your loop that completes any partial last row. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 17, 2012 Share Posted April 17, 2012 <?php $num_col = 3; $col = 0; echo '<div class="resultados_sub_cat">'; echo "<table>"; foreach($this->subcats as $key => $subcat) { // start a new row if($col == 0){ echo "<tr>"; } $subcat->link = JRoute::_('index.php?option=classcliff&view=list&catid='.$subcat->id."&Itemid=".$this->Itemid); //if ($key != 0) //echo ' - '; echo '<td><a href="'.$subcat->link.'">'.$subcat->name.'</a></td>'; $col++; // count the column you just output if($col >= $num_col){ echo "</tr>\n"; // end the row $col = 0; // reset counter } } // finish any partial last row if($col !== 0){ while($col < $num_col){ echo "<td> </td>"; $col++; } echo "</tr>"; } echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
jodancer Posted April 17, 2012 Author Share Posted April 17, 2012 Thank you so much! Worked perfectly Have a great day Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.