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?

Recommended Answers

All 3 Replies

Member Avatar for diafol

Try:

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

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!

Member Avatar for diafol

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.