html table built dynamically in php
table content from data
dog name | dog color |
Tairo | brown |
Emi | white |
Joy | black |
Lucky | yellow |
- This page is prepared by static html code.
- The table is prepared with php code dynamically.
- using php code, get data from mysql db server.
- This page is not request by a REST GET, (not ajax).
- return to the previous page by the link back
// php code as below:
echo "";
echo "";
echo "dog name | dog color | ";
echo "
";
while($row = mysqli_fetch_assoc($result)) {
echo '';
foreach ($row as $key => $value){
echo "" . $value . " | ";
}
echo '
';
};
echo "
";
- Loop each row with php method mysqli_fetch-assoc,
- not use for loop, and row index.
- for each row, use php method foreach,
- in the method argument, cast the row to key value pair.
- prepare the html table code accordingly.