0

Trying to learn PHP from a book and I swear I'm going balder by the minute!!

Anyway heres my predicament;

I want to display some simple incrementing data from a PHP loop within a table. So that each cell within the table displays a different value ie. cell 1 displays '1' cell 2 displays '2'

using a simple 'for' statment

for ($i=1;$i<10;$i++)

I either try

<table>
 <tr>
	<th>Numbers</th>
 </tr>
 <tr<?php for ($i=1;$i<10;$i++)?> >
	<td><?php echo $i?></td>
 </tr>
</table>

and end up with the last number on it's own

or

<table>
 <tr>
	<th>Numbers</th>
 </tr>
 <tr<? >
	<td><?php for ($i=1;$i<10;$i++) echo$i ?></td>
 </tr>
</table>

I just end up with all the values displayed in one cell

Am I not puttin the </td> tags in the right place, any help would be much appreciated?

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by diafol
0

Try:

<table>
 <tr>
	<th>Numbers</th>
 </tr>
	<?php for($i=1;$i<10;$i++) echo "<tr><td>$i</td></tr>"; ?>
</table>
0

Try:

<table>
 <tr>
	<th>Numbers</th>
 </tr>
	<?php for($i=1;$i<10;$i++) echo "<tr><td>$i</td></tr>"; ?>
</table>

Thanks worked like clockwork!

0

Great. Are we solved? If so click the Mark as Solved link. :)

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.