I need to add a nested table to my php page so that when I put it in my browser, just a table will appear with 2 columns and 3 rows. In the top left column I need the word "WIDTH", and right below that it will say "HEIGHT". The bottom box should be merged with a "SUBMIT" button. The top right and middle boxes will be blank, but when you add numbers to the 2 boxes, ie. 3 on top and 4 in the middle and hit the "SUBMIT" button, a 3 X 4 tables will come up. You should be able to add any numbers to the boxes and that size table will come up ie. 10 X 10 and so on. Can anyone please give me a hand. Below is what I have and I just can't figure it out. I guess it's called a nested loop construct. I appreciate any help that I get!
Respectfully
<?php
$width = 10;
$height = 10;
functionreateTable($width, $height)
{
$i =1;
$table = '<table border = "1">';
for ($r = 0; $r <$width; $c++)
{
$table .= '<tr>';
for <table ,= "<td> $i </td>;
$ i++;
}
$table .= <tr>';
}
$table .= '</table>';
return $table;
}
echo createTable ($width, $height);
?>
burt.munn
0
Light Poster
Recommended Answers
Jump to PostThat code is all to hell. Did you cannibalize the code from here: http://www.daniweb.com/web-development/php/threads/476020/xhtmlphp-table
You would probably find javascript better than php for this. Although either could be used I suppose.
Jump to PostDemo code:
<?php $useJS = (isset($_GET['usejs'])) ? 1 : 0; function createTable($rows,$cols) { $i=1; $output = '<p>Produced by <span class="php">PHP</span></p><table class="php">'; for($r=0;$r<$rows;$r++) { $output .= '<tr>'; for($c=0;$c<$cols;$c++) { $output .= '<td>'.$i.'</td>'; $i++; } $output .= '</tr>'; } $output .= '</table>'; return $output; } ?> <!DOCTYPE HTML> <html> …
All 9 Replies
diafol
diafol
burt.munn
0
Light Poster
diafol
burt.munn
0
Light Poster
diafol
burt.munn
0
Light Poster
burt.munn
0
Light Poster
diafol
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.