我写的代码有效,但我仍然坚持:
注意:未定义的索引:第35行的C:\ xampp \ htdocs \ portfolio \ periode4 \ graden \ array.php中的id。
有谁知道我要采取什么措施来取消通知?
<?php
function connect()
{
// Make a MySQL Connection
$link = mysqli_connect("localhost", "root", "", "school") or die(mysqli_error());
return $link;
}
if($_GET) {
$id = $_GET["id"];
}
// select query
$query = "SELECT * FROM graden" ;
$result = mysqli_query(connect(),$query);
// tabel maken
$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 )) {
$table .="<tr ".($_GET['id'] == $row['id']?" style='background-color:yellow'":"").">";
// 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 == "id")
{
$table .="<td><a href='array.php?id=$value'>$value</a></td>";
}
else
{
$table .="<td>$value</td>";
}
}
$table .= "</tr>";
}
$table .="</table>";
echo $table;
// optie lijst
//maken select query
$query = "SELECT id, temp FROM graden ";
//uitvoeren select query
$result = mysqli_query(connect(), $query) ;
//tonen alle gegevens
$select = "
<form action=\"array.php\" method=\"get\">\n
<select name=\"id\">\n
<option value='id'>---all---</option>\n
";
while($row = mysqli_fetch_assoc( $result ))
{
$select .= "<option value='".$row['id']."'>".$row["temp"]."</option>\n";
}
$select .= "</select>\n";
$select .= "<input type=\"submit\">\n";
$select .= "</form>\n";
echo $select;
答案 0 :(得分:1)
如果网址上没有id
参数,那么当然会失败:
$table .="<tr ". ($_GET['id'] == $row['id']?" style='background-color:yellow'":"").">";
尝试
$table .="<tr ". ( isset($_GET['id']) && $_GET['id'] == $row['id']?" style='background-color:yellow'":"").">";
但这可能会破坏逻辑,你需要检查..