Jump to content

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

...

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.