-1

我编写的代码有效,但我仍然不断收到:

注意:未定义的索引:第 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;
4

1 回答 1

1

id如果URL上没有参数,这当然会失败:

 $table .="<tr ". ($_GET['id'] == $row['id']?" style='background-color:yellow'":"").">";

尝试

 $table .="<tr ". ( isset($_GET['id']) && $_GET['id'] == $row['id']?" style='background-color:yellow'":"").">";

但这可能会破坏逻辑,你需要检查..

于 2013-06-20T15:51:14.643 回答