matthew_ellis24 Posted November 8, 2007 Share Posted November 8, 2007 Hello, I've had a crack at this using JOIN, and as shown below, but so far no luck. I decided against using JOIN because I don't want it to list habitats that don't have associated countries. $habitatcountry_id was defined from a database populated dropdown limited to countries with habitats as the country_id. But the code below produces the following error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /export/users/mbe/pages/carabus/habitat_country.php on line 6 If I echo $habitatcountry_id it echos the right code, so obviously my query is wrong. (???) As always, any help greatly appreciated! Thanks Matt $query= " SELECT DISTINCT habitat.habitat_name, habitat_country.habitat_id FROM habitat, habitat_country WHERE habitat.habitat_id = habitat_country.habitat_id AND habitat_country.country_id= $habitcountry_id ORDER BY habitat.habitat_name"; $result = mysql_query ($query); while ($myrow = mysql_fetch_array($result, MYSQL_ASSOC)){ echo $myrow['habitat_name']; } Quote Link to comment https://forums.phpfreaks.com/topic/76494-conditional-select-between-two-tables/ Share on other sites More sharing options...
Barand Posted November 8, 2007 Share Posted November 8, 2007 But you aren't usng $habitatcountry_id in the query. Quote Link to comment https://forums.phpfreaks.com/topic/76494-conditional-select-between-two-tables/#findComment-387726 Share on other sites More sharing options...
fenway Posted November 8, 2007 Share Posted November 8, 2007 I would have preferred if you had continued your original thread so that newcomers won't have to guess where you started.... Quote Link to comment https://forums.phpfreaks.com/topic/76494-conditional-select-between-two-tables/#findComment-387806 Share on other sites More sharing options...
matthew_ellis24 Posted November 8, 2007 Author Share Posted November 8, 2007 sorry even more embarrassingly I figured out (after 12 hours!) that this doesn't work because of a typo. Think I'd better give up on web design and go back to biological science! Quote Link to comment https://forums.phpfreaks.com/topic/76494-conditional-select-between-two-tables/#findComment-387822 Share on other sites More sharing options...
fenway Posted November 8, 2007 Share Posted November 8, 2007 sorry even more embarrassingly I figured out (after 12 hours!) that this doesn't work because of a typo. Think I'd better give up on web design and go back to biological science! Biological sciences? Which one? I have an MSc in biochemistry... Quote Link to comment https://forums.phpfreaks.com/topic/76494-conditional-select-between-two-tables/#findComment-387859 Share on other sites More sharing options...
Barand Posted November 8, 2007 Share Posted November 8, 2007 12 hours? I pointed it out to you after 8 hrs Quote Link to comment https://forums.phpfreaks.com/topic/76494-conditional-select-between-two-tables/#findComment-387862 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.