HOW TO FETCH DATA FROM MYSQL WITH WHERE CONDITION USING PHP - CULT CODE
In this tutorial, we will learn how to fetch Selected rows from a table in PHP with the WHERE condition.
1. Create a table name user.
Use the code below to create a table:
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`name` varchar(251) NOT NULL,
`email` varchar(251) NOT NULL,
`password` varchar(251) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
2. Now create a file connect.php:
This file will help us to connect PHP to Mysql.
<?php
$connect = mysqli_connect("localhost", "root", "password", "demo");
?>
3. Now create a file index.php:
Paste the below code in your index.php file.
<?php
include('connect.php');
$data_query = "SELECT * FROM user WHERE id='5'";
$data_result = mysqli_query($connect, $data_query);
if(mysqli_num_rows($data_result) > 0)
{
while($row = mysqli_fetch_array($data_result))
{
?>
Name: <?php echo $row['name']; ?><br>
Email: <?php echo $row['email']; ?><br><br>
<?php
}
}
?>



Comments
Post a Comment