Untitled Document
Here we are goingto join two tables with common column named
Emp'Age' Table
Emp | Age |
Ron White | 32 |
Femina | 65 |
John | 25 |
Don | |
'Salary_Emp' Table
Salary | Emp |
40000 | Ron White |
29000 | Femina |
25000 | |
11000 | Ron White |
The important thing to note here is that the column Emp contains information that can tie these two tables together. In the "Age" table, the Emp column contains all the Employee of the Company and their respective ages. In the "Salary_Emp" table the Emp column contains the respective Salary of the Employee.
It's only through a shared column relationship such as this that tables can be joined together, so remember this when creating tables you wish to have interact with each other.
//php start
// Make a MySQL connection using your database credentials
// Construct our join query
$query = "SELECT Age.Emp, Salary_Emp.Salary ".
"FROM Age, Salary_Emp".
"WHERE Age.Emp = Salary_Emp.Emp";
$result = mysql_query($query) or die(mysql_error());
// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
echo $row['Emp']. " - ". $row['Salary'];
echo "
";
}
//php ends
|
Emp | Salary |
Ron White | 40000 |
Femina | 29000 |
Ron White | 11000 |
No comments:
Post a Comment