我在数据库中有一个表。当我输入.../array.php?id=1
网址时,它将突出显示该行。如果我id=2
输入,那么它将突出显示第 2 行。
到目前为止,这是我的代码:
<?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;
?>