Today we are going to learn how to display data from database in PHP
First create a database in mysql
create database databasename;
create a table named one or any name
create table one(name varchar(20));
insert into one values('sample1');
insert into one values('sample2');
create a php page to display data from database
Quote:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Display data from database by s2sgateway.com </title>
</head>
<body>
<?php
$host="localhost";
$user="yourmysqlusername";
$pass="yourmysqlpassword";
$se=mysql_connect($host,$user,$pass);
if($se)
{
print_r ("connected");
}
else
{
print_r (mysql_error());
}
$s1=mysql_select_db("dbname",$se);
if($s1)
{
print_r("database working");
}
else
{
echo mysql_error();
}
echo $s1;
$new=mysql_query("select * from one");
while($row = mysql_fetch_array($new))
{
echo "results".$row['name'];
}
?>
</body>
</html>
Any doubt ask us.
Happy coding.