I have a table in a database and my question is how can I create it ... that when I type .../array.php?id=1 into the url, it will highlight that row. If I put id=2 in, then it will highlight row 2
Code:
<?php
function connect(){
// Make a MySQL Connection
$link = mysqli_connect("localhost", "root", "", "school") or die(mysqli_error());
return $link;
}
if ($_GET)
{
if(isset($_GET["id"])) $id = $_GET["id"];
}
// select query
$query = "SELECT * FROM graden" ;
if (isset($id)) { $query.= " WHERE id = $id "; }
$result = mysqli_query(connect(),$query);
// table making
$table = "<table border='1'>";
$table .= "<tr>
<th> ID </th>
<th>Graden Celcius</th>
<th>Aanduiding</th>
<th>Image</th>
</tr>";
// keeps getting the next row until there are no more to get
while($row = mysqli_fetch_assoc( $result )) {
// Print out the contents of each row into a table
foreach ($row as $key => $value) {
if ($key == "Image") {
$table .="<td><img src='$value' /></td>";
} elseif ($key == "temp") {
$table .="<td><a href='array.php?id=$value'>$value</a></td>";
} else {
$table .="<td>$value</td>";
}
}
$table .= "</tr>";
}
$table .="</table>";
echo $table;
?>
Comment