Ask Question


Retrieve Data From MySQL Using PHP

For retrieve data from MySQL the SELECT statement is used. We can retrieve data from specific column or all column of a table.

To retrieve selected column data from database the SQL query is

SELECT column_name,column_name FROM table_name;

To retrieve all the column data from a table the SQL query is

SELECT * FROM table_name;

In the below example we retrieve the data from MySQL database.

In this example we used 2 file for retrieve data


die('Could not Connect My Sql:' .mysql_error());


include_once 'database.php';
$result = mysqli_query($conn,"SELECT * FROM myusers");
<!DOCTYPE html>
<title> Retrive data</title>
<td>First Name</td>
<td>Last Name</td>
<td>Email id</td>
while($row = mysqli_fetch_array($result)) {
<tr class="<?php if(isset($classname)) echo $classname;?>">
<td><?php echo $row["first_name"]; ?></td>
<td><?php echo $row["last_name"]; ?></td>
<td><?php echo $row["city_name"]; ?></td>
<td><?php echo $row["email"]; ?></td>


table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
tr:nth-child(even) {
background-color: white;

Related Topic

Fetch data show in select box

Fetch data show in checkbox

Fetch data show in radio button

Fetch data show in text box

Buy Template