First of all, I am totally new to PHP, so I apologize for my coding mistakes.
I really need to figure out a way to do this:
After retrieving some data from a table called table1, I will store that data in a variable called employee. (This is easy enough.)
Furthermore I want to use that data which is now stored in the variable employee in an effort to retrieve some other data from another table (called table2) on the same database.
Said another way: The data-extraction which come out from table2, is dependent on the outcome of the data-extraction from table1.
Please explain the solution as simple as possible, since I am totally new to both PHP and mysql.
I've tried to show with code what I mean. I know it's not working, but hopefully you get the idea. Please correct me also if I have any other syntax flaws:
Code: Select all
<?PHP
//connect to database
mysql_connect(****, ******, ******) or die(mysql_error());
mysql_select_db(******) or die(mysql_error());
//select data from table1
$result1 = mysql_query('SELECT LastName FROM Table1 WHERE FirstName="John"');
$row = mysql_fetch_array($result1)
$employee = $row['LastName'];
//select data from table2, based on data from table1.
$result2 = mysql_query("SELECT wage FROM Table2 WHERE employee=$employee);
$row = mysql_fetch_array($result2)
$wage = $row['wage'];
mysql_close();
?>