Hello Im new in PHP and have some troubles. I have a mysql table called Services. I want to show some columns of that table in a html table. The problem is that I dont how to pass the entities as column and the atributes as rows. Pleas开发者_StackOverflowe help me!!
For example, I have a table cars
with fields in select. Here is how you do it. Assume $conn
is my mysql connection.
<?php
echo '<table>';
echo '<tr>';
echo '<th>id</th>';
echo '<th>make</th>';
echo '<th>model</th>';
echo '<th>vin</th>';
echo '</tr>';
$result = mysql_query($conn, 'SELECT id, make, model, vin FROM cars');
while (($row = mysql_fetch_array($result, MYSQLI_ASSOC)) != NULL) {
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['make'] . '</td>';
echo '<td>' . $row['model'] . '</td>';
echo '<td>' . $row['vin'] . '</td>';
echo '</tr>';
}
mysql_free_result($result);
echo '</table>';
?>
You were close. I made a few changes. Does this work as expected?
<?php
echo '<table>';
echo '<tr>';
echo '<th>id</th>';
echo '<th>make</th>';
echo '<th>model</th>';
echo '<th>vin</th>';
echo '</tr>';
$result = mysqli_query($conn, 'SELECT id, make, model, vin FROM cars');
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['make'] . '</td>';
echo '<td>' . $row['model'] . '</td>';
echo '<td>' . $row['vin'] . '</td>';
echo '</tr>';
}
mysqli_free_result($result);
echo '</table>';
?>
精彩评论