PHP Select Data From MySQL

The SELECT statement is used to select data from one or more tables:

include (‘function/db.php’);
global $conn;

$id = “1”;

$query = “SELECT * FROM table WHERE id=’$id'”;
$result = $conn->query($query);
$row = $result->fetch_assoc();

$id = $row[‘id’];
$data1 = $row[‘col1’];
$data2 = $row[‘col2’];

        $data3 = $row[‘col3’];
        $data4 = $row[‘col4’];

And you can show your result anywhere on your web page like –

Name  = <h1><?php  echo $data1 ?></h1>

Address  = <p><?php  echo $data2 ?></p>

Published by Sushant Sharma

Technologist. Software Developer. Tech Analyst ।।।

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started