<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "customer";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Select data from the customer table
$sql = "SELECT id, firstname, lastname FROM customer";
$result = $conn->query($sql);
// Check if there are any rows in the result set
if ($result->num_rows > 0)
{
// Output data of each row
while($row = $result->fetch_assoc())
{
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
// Close connection
$conn->close();
?>
for database
CREATE TABLE customer (
id INT,
firstname VARCHAR(50),
lastname VARCHAR(50),
contact VARCHAR(50),
address VARCHAR(100)
);
INSERT INTO customer (id, firstname, lastname, contact, address)
VALUES (1, 'Ram', 'Kumar', 'ram.kumar@abc.com', 'Tinkune, Kathmandu'),
(2, 'Shyam', 'Bahadur', 'shyam.bahadur@abc.com', 'Koteswor, Kathmandu'),
(3, 'Harry', 'Prasad', 'harry.prasad@abc.com', 'Imadol, Lalitpur'),
(4, 'Sita', 'Kumari', 'sita.kumari@abc.com', 'Sano Thimi, Bhaktapur');
It displays only first name and last name from the customer table in the database