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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.