Breaking

LightBlog

Saturday 4 July 2015

Select Data from database using PHP

Select Data from database using PHP

Data can store in table. After complete successfully submit Data in Database You can retrieve the data from database. You can retrieve the data from MySQL tables by executing SQL SELECT Statement through PHP function mysql_query. You can several option to fetch data from MySQL.
                                      
Select Data from database using PHP
The mysql_fetch _array( ). This function returns row as an associative array , numeric array or both.

Syntax: select  column name from table_name.

Or we can use the * character to select all columns from a table
Select *from student;

Example:
<?php
$con=mysql_connect(“localhost”, “deep “, 12345);
if (!$con)
{
die(“could not be connect the database” . mysql_error());
}
echo “ connected successfully “;

mysql_select_db ( “student”);
$result=mysql_query (“select *from  student”);
echo “<table border=1>”;
echo  “<tr><th>Name </th><th>Age</th></tr>”;
while ($row=mysql_fetch_array ($result))
{
echo “<tr><td>”;
echo $row [‘name’];
echo “</td><td>”;
echo $row [‘age’];
echo “</td></tr>”;
}
echo “</table>”;
?>
Adbox