怎么回声整个表? 现在我只得到最后一排

I have this code right now and I only get the last two rows, but I need to get as many as there are in the database with the html. Thank you in advance

      //We include the includes.php, which contains our db connection data.
       include("includes.php"); 
       //dbCon(); references the db connection data in includes.php - in other words we call a function.
     dbCon();
     $query = "SELECT * FROM product WHERE categoryid = 1;";
    $result = mysqli_query($dbc,$query) or die('Error querying database.');
      if (mysqli_num_rows($result) == NULL) {
     mysqli_close($dbc);header("Location:index.php?l=f");exit();
      }

    while ($row = mysqli_fetch_assoc($result)){
       $name = $row['name'];
        $price = $row['price'];
}

    echo "<input type='checkbox' name='name' value='name'>".$name."</br>";
    echo "Price: "." "."<strong>".$price."</strong></br>";

Move the echo to inside the loop

while ($row = mysqli_fetch_assoc($result)){
    $name = $row['name'];
    $price = $row['price'];
    echo "<input type='checkbox' name='name' value='name'>".$name."</br>";
    echo "Price: "." "."<strong>".$price."</strong></br>";

    }

Your echo code has to be inside the loop. Your edited code has to be like this:

//We include the includes.php, which contains our db connection data.
    include("includes.php"); 
    //dbCon(); references the db connection data in includes.php - in other words we call a function.
    dbCon();
    $query = "SELECT * FROM product WHERE categoryid = 1;";
    $result = mysqli_query($dbc,$query) or die('Error querying database.');
    if (mysqli_num_rows($result) == NULL) {
    mysqli_close($dbc);header("Location:index.php?l=f");exit();
    }

    while ($row = mysqli_fetch_assoc($result)){
    $name = $row['name'];
    $price = $row['price'];
    echo "<input type='checkbox' name='name' value='name'>".$name."</br>";
    echo "Price: "." "."<strong>".$price."</strong></br>";
    }

The problem is that you overwrite the $name and $price variables in each loop. So at the end of the while loop you will have the data stored in your variables from the last row.

The solution is to echo them in each loop, or collect the output of each iteration in a variable and then print it once at the end.

$output = '';
while ($row = mysqli_fetch_assoc($result)){
        $name = $row['name'];
        $price = $row['price'];
        $output .= "<input type='checkbox' name='name' value='name'>".$name."</br>";
        $output .= "Price: <strong>".$price."</strong></br>";  
}
echo $output;

Or simply:

while ($row = mysqli_fetch_assoc($result)){
        $name = $row['name'];
        $price = $row['price'];
        echo"<input type='checkbox' name='name' value='name'>".$name."</br>";
        echo "Price: <strong>".$price."</strong></br>";  
}