Skip to content

Instantly share code, notes, and snippets.

@jeanmarc
Created February 28, 2020 15:07
Show Gist options
  • Save jeanmarc/581be88163c1ae86ffcfdc839a987f77 to your computer and use it in GitHub Desktop.
Save jeanmarc/581be88163c1ae86ffcfdc839a987f77 to your computer and use it in GitHub Desktop.
Voorbeeld van een php sql query (bron: https://www.geeksforgeeks.org/php-mysql-select-query/)
<?php
$link = mysqli_connect("localhost", "root", "", "Mydb");
if ($link == = false) {
die("ERROR: Could not connect. "
.mysqli_connect_error());
}
$sql = "SELECT * FROM Data";
if ($res = mysqli_query($link, $sql)) {
if (mysqli_num_rows($res) > 0) {
echo "<table>";
echo "<tr>";
echo "<th>Firstname</th>";
echo "<th>Lastname</th>";
echo "<th>age</th>";
echo "</tr>";
while ($row = mysqli_fetch_array($res)) {
echo "<tr>";
echo "<td>".$row['Firstname']."</td>";
echo "<td>".$row['Lastname']."</td>";
echo "<td>".$row['Age']."</td>";
echo "</tr>";
}
echo "</table>";
mysqli_free_res($res);
}
else {
echo "No matching records are found.";
}
}
else {
echo "ERROR: Could not able to execute $sql. "
.mysqli_error($link);
}
mysqli_close($link);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment