php mysql_fetch_row

In php mysql_fetch_row() function returns result in a numerical array corresponding to the fetched rows.Offset 0,1 and 2 etc. are used for first column,2nd column and 3rd column etc. respectively.If there are no rows it returns FALSE.As in example we have table employees in mysql database.


id first_name last_name salary city
1 Johan Sumith 200000 Delhi
2 Ansh Kumar 300000 Mumbai
3 Sameer Seth 100000 Delhi
4 Pyush 250000 Kolkata
5 Shikha Anand 160000 Chandigarh
6 Rajeev Khatri 450000 Chennai
7 Ram Kumar 540000 Amritsar
8 Ritu Sharma 500000 Sonepat
9 Deepika Verma 360000 Chandigarh
10 Kuldeep Singh 270000 Simla
Now we want to fetch those records where salary is greater than 4,00,000.
<?php
$host="localhost";
$username="user_name";
$password="password";
$db="database_name";
$link=mysql_connect($host,$username,$password);
if($link)
{ //connection is opened
mysql_select_db($db,$link) or die("could not select database".mysql_error());
$query="SELECT * FROM employees WHERE salary>400000";
$result=mysql_query($query);
while($arr=mysql_fetch_array($result)){
	  //1=first_name  2=last_name   3=salary
echo 	$arr[1]." ".$arr[2]." ".$arr[3]."<br/>";
}
mysql_close($link);
}
else
 { //otherwise gives error
  echo mysql_error();
  }
?>