Jump to content

conditional SELECT between two tables


matthew_ellis24

Recommended Posts

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'];
}

Link to comment
https://forums.phpfreaks.com/topic/76494-conditional-select-between-two-tables/
Share on other sites

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

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.