1<?php
2 ////////////neha jaiswal///
3$serve="localhost";
4$user="root";
5$password="";
6$db="neha";
7$con=mysqli_connect($serve,$user,$password,$db);
8 if ($con) {
9 echo "connection success";
10 }else
11{echo "connection unsuccess"; }
12 $query="SELECT * FROM product";
13 $result=$con->query($query);
14 if($result->num_rows>0){
15 while($row=$result->fetch_assoc())
16 {
17 echo $name=$row['name'];
18 echo $qty=$row['qty'];
19 echo $price=$row['price'];
20 echo $image=$row['image'];
21 }
22 }
23
24?>
1
2<!DOCTYPE html>
3<html>
4<head>
5<title>Read Data From Database Using PHP - Demo Preview</title>
6<meta content="noindex, nofollow" name="robots">
7<link href="style.css" rel="stylesheet" type="text/css">
8</head>
9<body>
10<div class="maindiv">
11<div class="divA">
12<div class="title">
13<h2>Read Data Using PHP</h2>
14</div>
15<div class="divB">
16<div class="divD">
17<p>Click On Menu</p>
18<?php
19$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server
20$db = mysql_select_db("company", $connection); // Selecting Database
21//MySQL Query to read data
22$query = mysql_query("select * from employee", $connection);
23while ($row = mysql_fetch_array($query)) {
24echo "<b><a href="readphp.php?id={$row['employee_id']}">{$row['employee_name']}</a></b>";
25echo "<br />";
26}
27?>
28</div>
29<?php
30if (isset($_GET['id'])) {
31$id = $_GET['id'];
32$query1 = mysql_query("select * from employee where employee_id=$id", $connection);
33while ($row1 = mysql_fetch_array($query1)) {
34?>
35<div class="form">
36<h2>---Details---</h2>
37<!-- Displaying Data Read From Database -->
38<span>Name:</span> <?php echo $row1['employee_name']; ?>
39<span>E-mail:</span> <?php echo $row1['employee_email']; ?>
40<span>Contact No:</span> <?php echo $row1['employee_contact']; ?>
41<span>Address:</span> <?php echo $row1['employee_address']; ?>
42</div>
43<?php
44}
45}
46?>
47<div class="clear"></div>
48</div>
49<div class="clear"></div>
50</div>
51</div>
52<?php
53mysql_close($connection); // Closing Connection with Server
54?>
55</body>
56</html>
57Copy
1
2CREATE DATABASE company;
3CREATE TABLE employee(
4employee_id int(10) NOT NULL AUTO_INCREMENT,
5employee_name varchar(255) NOT NULL,
6employee_email varchar(255) NOT NULL,
7employee_contact varchar(255) NOT NULL,
8employee_address varchar(255) NOT NULL,
9PRIMARY KEY (employee_id)
10)
11Copy
1 <?php
2 //////neha jaiswal////
3 include 'config.php';////incluude data base connection file
4 $stmt = $conn->prepare('SELECT * FROM `product`');///select all data from database
5 $stmt->execute();////query execute ($stmt)
6 $result = $stmt->get_result();
7 while ($row = $result->fetch_assoc()):
8 ?>
9 <div class="card p-2 border-secondary mb-2">
10 <img src="<?= $row['product_image'] ?>" class="card-img-top" height="250">
11 <div class="card-body p-1">
12 <h4 class="card-title text-center text-info"><?= $row['product_name'] ?></h4>
13 <h5 class="card-text text-center text-danger"><i class="fas fa-rupee-sign"></i><?= number_format($row['product_price'],2) ?>/-</h5>