Jump to content

sql join


deansaddigh

Recommended Posts

How can i join my tables i have this sql

 

$locationSQL='SELECT county_id FROM properties  WHERE status = \'online\' order by location ASC';
$locationResults = $db->query($locationSQL);

 

but i have a county table with fields id and county

i need to be able to access county so i can fill a option box with the county

 

 

Link to comment
https://forums.phpfreaks.com/topic/188045-sql-join/
Share on other sites

OK i have managed to get them to join using this

 

$locationSQL='SELECT p.county_id, c.county 
FROM properties p 
JOIN county c
ON p.county_id = c.county  
WHERE status = \'online\' order by location ASC';
$locationResults = $db->query($locationSQL);

 

Now i should be able to access county on the county table.

 

But the option boxes arnt getting filled with the county.

 

 

<select name='location' class='searchDropDown' style='margin-top:5px;'>
			<option value='' <? if ( $location == '' ){echo 'selected';}?>>County</option>
<?		foreach($locationResults as $locationResults2)
	{

?>			<option value='<?=$locationResults2{'county_id'}?>' <? if ( $location == $locationResults2{'county_id'} ){echo 'selected';}?>><?=$locationResults2{'county'}?></option>
<?		}
?>
	</select>

 

Please someone help, im on a deadline

Link to comment
https://forums.phpfreaks.com/topic/188045-sql-join/#findComment-992740
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.