Display data from a database through PHP


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


Similar Articles