Are tables the same for PHP
I am not understanding I have this right now is the tables for html will work with PHP or are they different. I understand how to do tables in HTML with the CSS but I am not to sure with PHP. I am new to PHP and this might 开发者_开发知识库be a stupid question to most of you. I am just hoping someone can explain so I have a better understanding of it.
I am still not understanding how to display something in a table.
The browser only reads html
.
PHP
is a programing language, interpreted by the server, used to generate html
that the browser reads.
That said there are no such thing as PHP
tables. Just do a table the normal way. Take a look at the example bellow that uses PHP to create a "dynamic" table. Now imagine that the $animals
gets pulled from a database...
Example:
my-table-generator.php
<?php
$animals = array("dog", "cat", "duck");
?>
<table>
<tr>
<?php
foreach($animals as $animal)
{
echo "<td>".$animal."</td>";
}
?>
</tr>
</table>
PHP helps you send dynamic HTML to the browser. The HTML always remain the same regardless of the backend language you are using. So just use regular HTML and use PHP to render it. For instance if you want to display multiple rows of some data coming from the DB, you will utilize a PHP loop to print out the <tr><td></td></tr>
example:
for($i = 0 ; $i < 10 ; $i++){
echo "<tr><td>$i</td></tr>";
}
Probably not a very good example but hopefully it will get the message across.
精彩评论