Jump to content

How to use Query the results of a query


yandoo

Recommended Posts

Hi there,

 

Im having real nightmare trying to query the results of a previous query......

 

Basically the page displays a most recent entered record into the database:

 

mysql_select_db($database_woodside, $woodside);

$query_animal = "SELECT * FROM animal ORDER BY AnimalID DESC";

$animal = mysql_query($query_animal, $woodside) or die(mysql_error());

$row_animal = mysql_fetch_assoc($animal);

$totalRows_animal = mysql_num_rows($animal);

 

The data it fetches is from the "Animal" table and includes a field called "AnimalTypeID" This field is the one that i want to query against another table("Breed") Both the Breed table and the Animal table share the same common field "AnimalTypeID"

 

I have tried usiing this query for that:

 

mysql_select_db($database_woodside, $woodside);

$query_Recordset1 = "SELECT BreedID FROM breed WHERE breed.AnimalTypeID = animal.AnimalTypeID";

$Recordset1 = mysql_query($query_Recordset1, $woodside) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

 

Please help me, imbecomming desperate.

 

Thank You :)

 

Link to comment
Share on other sites

Sounds like you need something like:

<?php
$sql = "SELECT breed.BreedID FROM breed,animal WHERE breed.AnimalTypeID = animalTypeId ORDER BY animal.AnimalID DESC LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
$breedID = mysql_result($result,0);
echo 'BreedID: '.$breedID;a
?>

 

Next time, try adding to your previous topic rather than creating a new one. Dont create two topics on the same subject.

 

Link to comment
Share on other sites

Hi there, only me again

 

 

 

Hmmm, no there it still not giving me the result  i need....

 

The breed list menu now offers ONLY a single Breed for example....if i added details on of an animal that was a DOG....I need the DOG attribute to be compared against the Breed table so ALL types of DOG BREED are displayed (like Alsation, Terrier etc.. at mo only brings up alsation). And if i added a CAT animal....The BREED should select all records of BREED that  are of the type of a CAT.

 

Thanks ever so much for helping me here

 

Kind Regards

 

Tom :)

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.