6
05/11/2024 8:46 am
Topic starter
Hi. I want to create table with PHP with 10 rows and 3 columns;Also it needs to be in HTML. How can I do it?
Thanks
2 Answers
5
05/11/2024 8:47 am
Here is mine with the escaped characters \n and \t (linefeed and horizontal tab):
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP Table </title> </head> <body> <?php $i = 1; echo "<table border='1'>\n"; while ( $i <= 10 ) { echo "\t<tr>\n"; $n = 1; while ( $n <= 3 ) { echo "\t\t<td>Row $i | Col $n</td>\n"; $n++; } echo "\t</tr>\n"; $i++; } echo '</table>'; ?> </body> </html>
See more about escaped characters HERE
4
05/11/2024 8:48 am
Here is the code (I've used while). See line #17 - I've used double quotes instead of singles ones:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <?php $i = 1; echo '<table border="1">'; while ( $i <= 10 ) { echo '<tr>'; $n = 1; while ( $n <= 3 ) { echo "<td>Row $i | Col $n</td>";//Use double quotes for $i and $n $n++; } echo '</tr>'; $i++; } echo '</table>'; ?> </body> </html>
...and the result in the browser:
You forgot to use \n (new row) and \t (tab)...