Skip to content

Commit

Permalink
Update index.php
Browse files Browse the repository at this point in the history
  • Loading branch information
milq authored May 17, 2017
1 parent 7f3ff5f commit f407536
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions learn/crud/sql/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,43 @@
<h1>Students</h1>

<a href='form.php'>Insert a new student</a><br /><br />

<?php
require_once('connect_db.php');

$sql = 'SELECT * FROM students';
$sth = $dbh->prepare($sql);
$sth->execute();
$rows = $sth->fetchAll();

echo '<table>';
echo '<tr>';
echo '<th>ID</th>';
echo '<th>First name</th>';
echo '<th>Last name</th>';
echo '<th>Nickname</th>';
echo '<th>Date of birth</th>';
echo '<th>Mark</th>';
echo '<th>Edit</th>';
echo '<th>Delete</th>';
echo '</tr>';

foreach ($rows as &$row) {
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['first_name'] . '</td>';
echo '<td>' . $row['last_name'] . '</td>';
echo '<td>' . $row['nickname'] . '</td>';
echo '<td>' . $row['date_of_birth'] . '</td>';
echo '<td>' . $row['mark'] . '</td>';
echo '<td><a href=\'form.php?id=' . $row['id'] . '\'>Edit</a></td>';
echo '<td><a href=\'process.php?delete=yes&id=' . $row['id'] . '\'>Delete</a></td>';
echo '</tr>';
}
<table title='student_table'>
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>Nickname</th>
<th>Date of birth</th>
<th>Mark</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
require_once('connect_db.php');

$sql = 'SELECT * FROM students';
$sth = $dbh->prepare($sql);
$sth->execute();
$rows = $sth->fetchAll();

echo '</table>';
?>
foreach ($rows as &$row) {
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['first_name'] . '</td>';
echo '<td>' . $row['last_name'] . '</td>';
echo '<td>' . $row['nickname'] . '</td>';
echo '<td>' . $row['date_of_birth'] . '</td>';
echo '<td>' . $row['mark'] . '</td>';
echo '<td><a href=\'form.php?id=' . $row['id'] . '\'>Edit</a></td>';
echo '<td><a href=\'process.php?delete=yes&id=' . $row['id'] . '\'>Delete</a></td>';
echo '</tr>';
}
?>
</tbody>
</table>
</body>
</html>

0 comments on commit f407536

Please sign in to comment.