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

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.