从Mysqli获取id

I've been trying to add a Modal to popup whenever i click a button to update the records i have stored in a database but i'm having trouble getting the id

    <?php

                                        //Open a new connection to the MySQL server
                                        $mysqli = new mysqli('localhost','root','','pizzeria');

                                        //Output any connection error
                                        if ($mysqli->connect_error) {
                                        die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
                                        }
                                        //MySqli Select Query
                                        $results = $mysqli->query("SELECT id, navn, indeholder, pris FROM pizza");
                                        print '<tr>';
                                        while($row = $results->fetch_assoc()) {
                                            print '<td>'.$row["id"].'</td>';
                                            print '<td>'.$row["navn"].'</td>';
                                            print '<td>'.$row["indeholder"].'</td>';
                                            print '<td>'.$row["pris"].'</td>';
                                            print '<td align="center"><button type="btn btn-default" data-toggle="modal" data-target="#<?php echo $row['id']; ?>">Redigere</button></td>';
                                            print '</tr>';                                          
                                            }
                                        // Frees the memory associated with a result
                                        $results->free();

                                        // close connection 
                                        $mysqli->close();

                                        ?>
                                    </tbody>
                                </table>
                            </div>
<div class="modal fade" id="delete-<?php echo $row['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Bekræft Venligst Sletning</h4>
      </div>
      <div class="modal-body">
        Er du sikker på at du vil slette <?php echo $rows['navn']; ?>?
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Luk</button>
        <a href="delete.php?id=<?php echo $rows['id']; ?>" class="btn btn-info btn-sm">Slet</a>
      </div>
    </div>
  </div>
</div>  

Is there anything i can do to fix it?

You're trying to call the $row variable outside of the while loop that it's defined in. You need to assign the array values from $row to new variables while you are in the loop. Then, you'll be able to reference the values in the second half of the script.

$id_array = array();
$nav_array = array();
$indeholder_array = array();
$pris_array = array();

while($row = $results->fetch_assoc()) {

    // Save the results to our globally scoped arrays
    array_push($id_array, $row["id"]);
    array_push($nav_array, $row["navn"]);
    array_push($indeholder_array, $row["indeholder"]);
    array_push($pris_array, $row["pris"]);

    echo '<td>'.$row["id"].'</td>';
    echo '<td>'.$row["navn"].'</td>';
    echo '<td>'.$row["indeholder"].'</td>';
    echo '<td>'.$row["pris"].'</td>';
    echo '<td align="center"><button type="btn btn-default" data-toggle="modal" data-target="#<?php echo $row['id']; ?>">Redigere</button></td>';
    echo '</tr>';                                          

}

In the above, I created four new arrays in the global scope to store each of the values returned from your SELECT query.

I also changed instances of print to echo. You'll want to use echo in place of print when generating HTML mark-up. print will evaluate the variables you pass into it and you might see wonky results if you use it to generate HTML.

Now when you want to grab these values in the second half of your script, you would use something like:

  <div class="modal-body">
      Er du sikker på at du vil slette <?php echo $nav_array[0]; ?>?
  </div>

Notice the 0 index key I am referencing when using the array. Change this to match the value you want to get from the results.

You're actually getting a PHP syntax error. On the 5th print inside the while loop:

print '<td align="center"><button type="btn btn-default" data-toggle="modal" data-target="#<?php echo $row['id']; ?>">Redigere</button></td>';

Change it to

print '<td align="center"><button type="btn btn-default" data-toggle="modal" data-target="#'.$row['id'].'">Redigere</button></td>';