Jump to content

Displaying only so many items in a row of a table


PHPTOM

Recommended Posts

Hi,

Im wanting a table to function like this:

*table coding*

<tr>

<td>1</td>

<td>2</td>

<td>3</td>

<td>4</td>

</tr>

<tr>

<td>5</td>

<td>6</td>

<td>7</td>

<td>8</td>

</tr>

 

I basically want it to go to a new row once it hits 4 items on the current row. Any ideas on how to do this?

I'm off to school now, but I will be sure to have a read when I get in if anyone replies

 

Thanks :)

 

<?php
// settings:
$number_of_rows = 6;
$number_of_columns = 4;

// start table
echo '<table><tr>';

// count number of elements, and divide by columns to get row count
for($i=0; $i/$number_of_columns<$number_of_rows; $i++) {

// if new row
if($i%$number_of_columns==0) 
	echo '</tr><tr>';

// show box.
echo '<td>',$i,'</td>';
}
echo '</tr></table>';
?>

 

That'll make:

0123

4567

...

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.