SIGN UP MEMBER LOGIN:    
ARTICLE

Display data from a database through PHP

Posted by Satyapriya Nayak Articles | PHP December 03, 2011
In this article we will learn how to display the records from the database using PHP. Before going forward we should know about WAMP Server. This is an environment where we can run your php scripts and create databases.
Reader Level:

WAMP Server

WAMPs are packages of independently created programs installed on computers that use a Microsoft Windows operating system.

WAMP is an acronym formed from the initials of the operating system Microsoft Windows and the principal components of the package: Apache, MySQL and one of PHP, Perl or Python. Apache is a web server. MySQL is an open-source database. PHP is a scripting language that can manipulate information held in a database and generate web pages dynamically each time content is requested by a browser. Other programs may also be included in a package, such as PHPMyAdmin, which provides a graphical user interface for the MySQL database manager, or the alternative scripting languages Python or Perl. Equivalent packages are MAMP (for the Apple Mac) and LAMP (for the Linux operating system).

Refer from http://en.wikipedia.org/wiki/WAMP

Installation of WAMP Server

We can download WAMP server from http://www.wampserver.com/en/download.php.

Step 1: Double click on WAMP Server setup.

WAMP

Click 'Next' button

Step 2: Select 'I accept the agreement' and then click 'Next button'.

WAMP in php

Step 3: 'c: \wamp' default directory where WAMP is going to install. Here we can browse any other directory to install it.

php WAMP

Click 'Next' button

Step 4: Select "Quick Launch icon' and 'Create a Desktop icon'. Not mandatory.

display data using php

Click 'Next' button.

Step 5: This is the confirmation window before installing setup will start.

php used to display data

Click 'Install' button.

Step 6: Installation begins.

WAMP

Click on 'Finish' button to exit setup.

WAMP installation

Step 7: After successful installation click on notification area of windows desktop.

install WAMP

To verify that installed Wamp server works properly or not. http://localhost

installing WAMP

Table creation

Server: localhost   Database: home_work
-- phpMyAdmin SQL Dump
-- version 2.10.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Nov 17, 2011 at 04:25 PM
-- Server version: 5.0.45
-- PHP Version: 5.2.5
 
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
 
--
-- Database: `home_work`
--

-- -------------------------------------------------------- 
--
-- Table structure for table `employee`
--
 
CREATE TABLE `employee` (
  `id` int(11) NOT NULL auto_increment,
  `empid` varchar(255) NOT NULL,
  `empname` varchar(255) NOT NULL,
  `empaddress` varchar(255) NOT NULL,
  `designation` varchar(255) NOT NULL,
  `salary` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
 
--
-- Dumping data for table `employee`
--  
INSERT INTO `employee` (`id`, `empid`, `empname`, `empaddress`, `designation`, `salary`) VALUES
(1, 'E001', 'Raj', 'Delhi', 'Clerk', 10000),
(2, 'E002', 'Harry', 'Mumbai', 'Player', 20000),
(3, 'E003', 'Sunil', 'Noida', 'Producer', 30000),
(4, 'E004', 'Pollock', 'Durban', 'Manager', 40000),
(5, 'E005', 'Jonty', 'Perth', 'Director', 50000),
(6, 'E006', 'Kallis', 'Oslo', 'Dean', 60000),
(7, 'E007', 'Imran', 'Dubai', 'Admin', 70000);

showDetails.php

<?php
$link=mysql_connect("localhost","root","");
mysql_select_db("home_work",$link);
$sql="SELECT * FROM employee ";
$aResult=mysql_query($sql);
 
?>
<html>
<head>
</head>
<body bgcolor="Yellow">
<form name="frmForm" id="frmForm" >
<table border="1" width="30%" height="30%"> 
<tr>
<th><font color='Red'>ID</font></th>
<th><font color='Red'>NAME</font></th>
<th><font color='Red'>ADDRESS</font></th>
<th><font color='Red'>DESIGNATION</font></th>
<th><font color='Red'>SALARY</font></th>
</tr> 

<?php

while($rows = mysql_fetch_array($aResult,MYSQL_ASSOC))

$id         = $rows['id'];
$empid              = $rows['empid'];
$empname         = $rows['empname'];
$empaddress   = $rows['empaddress'];
$designation  = $rows['designation'];
$salary       = $rows['salary']; 
?>
<tr>
 
<td><b><font color='#663300'><?php echo $empid;?></font></b></td>
<td><b><font color='#663300'><?php echo $empname;?></font></b></td>
<td><b><font color='#663300'><?php echo $empaddress;?></font></b></td>
<td><b><font color='#663300'><?php echo $designation;?></font></b></td>
<td><b><font color='#663300'><?php echo $salary;?></font></b></td>
 
</td>
</tr>
 
<?php } ?>
</table>
</form>
</body>
</html>

Running the application

Run the WampServer then write the below line in the URL

http://localhost/Display records from database/

WAMP used to display record

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Gauge for SharePoint
Become a Sponsor