Friday, 17 August 2007

Using Queries in PHP


This section, we will discuss more detailed about using queries in PHP for retrieving data from Mysql. As we know that for queri-ing something from Mysql in PHP, we must use mysql_query.

Let us see the following example:



NameGenderJob
JaneFemaleStudent
DianaFemaleStudent
JohnMaleStudent


According to the above table, if we want to show all data of the table. So we can use the following syntax:

include"connection.inc.php";
$strsql=mysql_query("SELECT * FROm t_student"); //assume that the table's name is t_student
while($data=mysql_fetch_array($strsql))
{
echo $data[name];
echo $data[gender];
echo $data[job];
}
?>

No comments:

by Google