Question


Himanshu

how to fetch data from database in php one by one ?

Date = 2015-03-23

Comments by experts


Rajesh Kakadiya
2015-03-23

<?php

$con
=mysql_connect("localhost","username","password"); // connection to localhost
if(!$con)
  {
  die(
'Could not connect :'.mysql_error()); // showing error if having problem with username or password
  
}
mysql_select_db("database_name",$con); // select database from localhost

$query=mysql_query("SELECT id,fname FROM register");

while(
$row=mysql_fetch_array($query))
{
    echo 
"id = ".$row['0']."First Name = ".$row['1']."<br>"// you can write colunm name in place of '0' and '1'
}

mysql_close($con// close connection to server 
?>


Type your Comment below and click to send comment