Jump to content

Archived

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

redarrow

tables.

Recommended Posts


does this look correct to you as i am learning how to use for loops to produce tables cheers.

[code]

<?php

echo"<html><body>";

$list1=array(green =>"red", red => "green", pink => "yellow", yellow => "pink",pink =>

"grey",grey => "orange", orange => "brown",brown => "blue");

foreach($list1 as $b => $a){

echo"<table align='center' border='4' bordercolor='black'>";

for($i=0; $i< 1; $i++){

echo "<tr><td width='60' align='center' bgcolor='$a'>$a</tr></td><td width='60'

align='center'bgcolor='$b'>$b</td>";

}
}
 
echo"</table></body></html>";
?>

[/code]

Share this post


Link to post
Share on other sites
maybe if you explained exactly what you were trying to do here.. cuz i'm looking at your script and there's no apparent sense to it. 

you are missing a < tr > .. < /tr > in your echo inside your for loop though

Share this post


Link to post
Share on other sites
I am trying to learn all the possabiltys with tables and for loops so that i dont need to hard code html.

if you got any examples with tables and for loops then post it m8 cheers.

Share this post


Link to post
Share on other sites
[code]<?php
$rows = 2;
$cols = 5;

$data = array(
array(
'1,1','1,2','1,3','1,4','1,5'
),
array(
'2,1','2,2','2,3','2,4','2,5'
),
);

echo "<table border='1'>\n";
for($row=0; $row<$rows; $row++)
{
echo "\t<tr>\n";
for($col=0; $col<$cols; $col++)
{
echo "\t\t<td>{$data[$row][$col]}</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>";
?>[/code]

Share this post


Link to post
Share on other sites

×

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.