i want to create a e commerce website using html, css and sq database. Because i have a hundreds of product i want to show the product automatically in it's own. Due to that i have need to use database of sq to show it on php. But the one im wondering is i know that to show sqlite database to php is possible, but how to use the php data to show in my html? do i need to use .php file instead of .html file? thank you.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "database";
$name = array();
$x=0;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "SELECT name, price, id FROM users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["name"]. " - Name: " . $row["price"]. " " . $row["id"]. "<br>";
$name[$x]=$row["name"];
$x=$x+1;
}
} else {
echo "0 results";
}
echo $name[2];
$conn->close();
?>
Aucun commentaire:
Enregistrer un commentaire