I have the following tables:
JOBS:
+--------+------------+------------------+
| job_id | company_id | job_title |
+--------+------------+------------------+
| 123456 | 342186 | MySQL Dev needed |
| 549201 | 175123 | PHP Dev needed |
| 784930 | 823491 | UI Designer pls |
+--------+------------+------------------+
COMPANIES:
+------------+--------------+---------------------+
| company_id | company_name | company_email |
+------------+--------------+---------------------+
| 342186 | Microsoft | microsoft@email.com |
| 823491 | Quora | quora@email.com |
| 784930 | Facebook | facebook@email.com |
+------------+--------------+---------------------+
This is my current Query for getting all jobs from the JOBS table:
// get all jobs from jobs table
$result = mysql_query("SELECT * FROM jobs") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// jobs node
$response["jobs"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$job = array();
$job["job_id"] = $row["job_id"];
$job["company_id"] = $row["company_id"];
$job["company_name"] = $row["company_name"]; //<<<-------THIS
$job["job_title"] = $row["job_title"];
// push single product into final response array
array_push($response["jobs"], $product);
}
else { //Error }
With the above code I get all jobs, now, How can I modify my query/code so that "company_name" belongs to the respective job? Example:
Since the job "Mysql Dev needed" was posted by company_id = 342186 then it belongs to Microsoft
I was thinking in making another while loop inside the actual while loop so that I can get the exact company info, but I do not believe is the best way.