lundi 28 novembre 2016

How do I correctly echo checkboxes in a PHP table?

I have a table which is full with data from my database. I am now trying to implement a delete feature on that table, I do have the correct syntax to echo checkboxes but I don't know how to format the line correctly so the corresponding checkbox aligns correctly with each row. Any ideas? (I currently have the line echo'd above the closing table tag. Which makes the boxes appear above the table)

    $query = "SELECT * FROM products";
    $result = mysqli_query($connection, $query);

    if ($result->num_rows > 0) 
    {
 echo "<table><tr><th>ID</th><th>Name</th><th>Description</th><th>Price</th><th>Cost Price</th><th>Stock</th><th>EAN</th><th>Delete Product</th></tr>";

 while($row = $result->fetch_assoc())
     {
     echo "<tr><td>" . $row["product_id"]
     . "</td><td>" . $row["product_name"]
     . "</td><td> " . $row["product_description"]
     . "</td><td> " . $row["product_price"]
     . "</td><td> " . $row["product_cost_price"]
     . "</td><td> " . $row["product_stock"]
     . "</td><td>" . $row["product_ean"]
     . "</td></tr>";
     echo '<input name="delete['.$row['product_id'].']" type="checkbox">';
     }
     echo "</table>";
    }
     else 
     {
     echo "0 results";
     }




Aucun commentaire:

Enregistrer un commentaire