Forum Home
Press F1
 
Thread ID: 55301 2005-03-07 10:29:00 Mysql and PHP help required - Queries joins Morgenmuffel (187) Press F1
Post ID Timestamp Content User
331642 2005-03-07 10:29:00 Hopefully the code below will show up nicely coloured



<?php
require_once('conn_inc.php');
mysql_select_db($dbname, $conn);
$query_result = "SELECT * FROM `job` ORDER BY 'job_ID' DESC LIMIT 2";
$result=mysql_query($query_result, $conn)OR DIE(mysql_error());

while ($row_result = mysql_fetch_array($result)) {
echo '<tr><td><a href="index.php?page_ID=13&job_ID=';
echo $row_result['job_ID'];
echo '">';
echo $row_result['job_name'];
echo '</a></td><td>';
echo nl2br($row_result['job_description']);
echo '</td><td>';
echo nl2br($row_result['job_experience']);
// echo '</td><td>';
// echo nl2br($row_result['job_location']);
echo '</td></tr>';
}
?>


The commented out code is whereI am having a problem

// echo '</td><td>';
// echo nl2br($row_result['job_location']);

job table (typical record)
job_id=3
job_name="brain surgeon"
job_description="yada yada"
job_experience="yada yada"
job_location="3"

Location table
location_ID=3
location_name="Southland"

location_ID is the same as job_location

My question is how do I alter my code so that I can display the location as Southland rather instead of "3", I have a horrible feeling I need some sort of join, but I am absolutly stumped

This is what I tried but it didn't work
SELECT * FROM `job`, 'location' where (job.job_location=location.location_ID)ORDER BY 'job_ID' DESC LIMIT 2

help would be appreciated
I'll post this efore the damn thing times out on me
Morgenmuffel (187)
331643 2005-03-07 10:49:00 Problem solved

tried my first left join and it worked first pop, after hours of trying all sorts of things with other joins


SELECT job_ID, job_name, job_description, location_name FROM job LEFT JOIN location on job.job_location = location.location_ID ORDER BY 'job_ID' DESC LIMIT 2

For some reason whenever i post a problem my brain starts working again

so thanks PressF1, got me out of panic mode long enough to solve the problem
Morgenmuffel (187)
1