Thursday 7 August 2014

How to fetch data from database in four simple step in php

Follow the Step:

Step 1: Select the host
Step2: Connect to the database
Step3:Create the fetch query  to reterive all data
Step4. Use mysqli_fetch_array() function .

My Table look like 
table










Index.php

<body>

<?php
$username = "root";
$password = "";
$hostname = "localhost";
$database_name='registration';
$dbhandle = mysqli_connect($hostname,$username,$password,$database_name)
or die("Unable to connect to MySQL");
$query="select *from user";
$abc=  mysqli_query($dbhandle,$query);
?>
 <center>
 <table border="1" cellspacing="1" cellpading>
<tr>
 <td>Id</td>
<td>Name</td>
<td>Password</td>
<td>Email</td>
</tr>
<?php
while ($row = mysqli_fetch_array($abc))
{
 echo "<tr align='center'>";
echo"<td><font color='black'>" .$row['id']."</font></td>";
echo"<td><font color='black'>" .$row['name']."</font></td>";
echo"<td><font color='black'>". $row['password']. "</font></td>";
echo"<td><font color='black'>". $row['email']. "</font></td>";
echo "</tr>";
}
?>
</table>
</center>
    </body>

Output
table


1 comment: