tags:

views:

24

answers:

2
    echo $s['name'] .": ". $result ."<br />\n";

That's my code echoing $sitename[] : $result[] Currently there are 3 sites that it echos. However I want it to echo it like so:

<table>
<tr>
<td>$sitename[0]</td>
<td>&nbsp;</td>
<td>$result[0]</td>
</tr>
<tr>
<td>$sitename[1]</td>
<td>&nbsp;</td>
<td>$result[1]</td>
</tr>
<tr>
<td>$sitename[2]</td>
<td>&nbsp;</td>
<td>$result[2]</td>
</tr>
</table>

And then automatically add additional rows when I add a $site[3] and $site[4]

I'm not sure if this makes sense, if not, let me know and I'll try to rephrase.

+1  A: 

So you will echo out the tags, then inside do a for loop for each site, echo out the rest of the values that way.For Loop Information

So for example...

echo "<table>";
for ( $counter = 0; $counter <= 2; $counter += 1) 
{
   echo "
   <tr>
   <td>" . $sitename[$counter] . "</td>
   <td>&nbsp;</td>
   <td>" . $result[$counter] . "</td>
   </tr>";
}
echo "</table>";

You can also look up for each loops if you are not sure how many sites you are adding, and want to create dynamic content.

IPX Ares
Thanks a lot! Works perfectly.
Rob
+1  A: 

Just to make it a little simpler, as IPX mentions you might want to use a for each.

IPX's Code using a Foreach:

echo "<table>";
foreach ( $sitename as $counter => $name) 
{
   echo "
   <tr>
   <td>" . $name . "</td>
   <td>&nbsp;</td>
   <td>" . $result[$counter] . "</td>
   </tr>";
}
echo "</table>";

Yes, it is basically the same thing, but I felt I should just put it out there.

Chacha102
Perfect approach as well, did not have time to flush out both, thanks!
IPX Ares