deansaddigh Posted January 11, 2010 Share Posted January 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188045-sql-join/ Share on other sites More sharing options...
deansaddigh Posted January 11, 2010 Author Share Posted January 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188045-sql-join/#findComment-992740 Share on other sites More sharing options...
deansaddigh Posted January 11, 2010 Author Share Posted January 11, 2010 Hi guys, i have it working now. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/188045-sql-join/#findComment-992772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.