So today i share with you , how to display data from SQL database with select query
in table format.
Here following easy two steps to write code.
1. DATABASE CONNECTION :
First we need established database connection to fetch data from DATABASE.conn.php
----------------------------------------------------
<?php
error_reporting(0);
mysql_connect('localhost','root',''); // this function is use of database connection.
mysql_select_db('database'); // this function is use to select database from server.
?>
----------------------------------------------------
In above code we have set the connection of Sql server database.
2. DISPLAY DATA IN TABLE FORMAT.
Now here , we write this following code for selecting data from database and display in table format.table.php
-----------------------------------------------------
<?php
include "conn.php"; // include connection file for the database connection.
?>
<html>
<head>
<title>Display Data </title>
</head>
<body>
<table border='1'>
<tr>
<th>No.</th><th>Firstname</th><th>Lastname</th><th>Email</th>
</tr>
<?php
$select="SELECT * FROM `userdetails` ORDER BY `No` ASC "; // this query is use for fetching data from table.
$exe=mysql_query($select); // execution of query
while($result=mysql_fetch_array($exe)) // this function looping at the last record.
{
?>
<tr>
<td><?php echo $result['No'];?></td>
<td><?php echo $result['firstname'];?></td>
<td><?php echo $result['lastname'];?></td>
<td><?php echo $result['email'];?></td>
</tr>
<?php } ?>
</table>
</body>
</html>-----------------------------------------------------
RESULT PREVIEW
Above code is display data in table format ,Here i dont write designing code and explain, because designing is depend on you .
you can download this code here ...
DOWNLOAD.zip
If you like this, then share with your friends. And if you have query, contact-me and give comment.
0 comments:
Post a Comment