.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Display Data From Database Through Php

Posted By:satyapriyanayak       Posted Date: January 31, 2014    Points: 200    Category: General    URL: http://www.dotnetspark.com  

In this article we will know how to display the records from the database using php. Before going forward we should about WAMP Server. This is an environment where we can run your php scripts and create database.
 

In this article we will know how to display the records from the database using php. Before going forward we should about WAMP Server. This is an environment where we can run your php scripts and create database.

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).


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.
 
Click 'Next' button
Step 2:  Select 'I accept the agreement' and then click 'Next button'.
 
Step 3: 'c: \wamp' default directory where WAMP is going to install. Here we can browse any other directory to install it.
 
Click 'Next' button
Step 4: Select "Quick Launch icon' and 'Create a Desktop icon'. Not mandatory.
 
Click 'Next' button.
Step 5: This is the confirmation window before installing setup will start.
 
Click 'Install' button.
Step 6: Installation begins.
 
Click on 'Finish' button to exit setup.
 
Step 7: After successful installation click on notification area of windows desktop.
 
To verify that installed Wamp server works properly or not. http://localhost



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/



 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend