mysql - How to automatically design a dynamic table when fetching row (PHP /MySQLi) -
i'd design dynamic table when fetching row in php/mysql. please see attached image of example.
see code below, works vertical bar in middle doesn't seems fit well.
for ($i = 0;$i<$result->num_rows;$i++){ $row = $result->fetch_array(mysqli_num); //echo "* ".$row["0"]."<br>"; // work great //echo "* " .$row["0"] .$row["1"] ."<br>"; echo "| " .$row["1"] ."               " ." | " ."   " .$row["2"] ."<br>"; }
what want do:
that example of how echo html tables php code
echo "<table><thead></thead><tbody>" ($i = 0;$i<$result->num_rows;$i++){ $row = $result->fetch_array(mysqli_num); echo "<tr>". "<td>{$row["0"]}</td>". "<td>{$row["1"]}</td>". "<td>{$row["2"]}</td>". "</tr>\n"; } echo "</tbody></table>"
css
td{ padding: 3px; /*add space directions (top, right,bottom, left)*/ padding-left: 6px; /*add space left side only*/ }
put css in css files of html document (it applied td
elements in document). or -which not recommended- inline-css this
echo "<tr>". "<td style='padding-left:6px'>{$row["0"]}</td>". "<td style='padding-left:6px'>{$row["1"]}</td>". "<td style='padding-left:6px'>{$row["2"]}</td>". "</tr>\n";
Comments
Post a Comment