yandoo Posted January 25, 2008 Share Posted January 25, 2008 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 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 25, 2008 Share Posted January 25, 2008 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. Quote Link to comment Share on other sites More sharing options...
yandoo Posted January 25, 2008 Author Share Posted January 25, 2008 OMG - I think it works!! Ill give it some tests - but thank you p.s. sorry bout reposting Quote Link to comment Share on other sites More sharing options...
yandoo Posted January 25, 2008 Author Share Posted January 25, 2008 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 Quote Link to comment Share on other sites More sharing options...
yandoo Posted January 25, 2008 Author Share Posted January 25, 2008 Any ideas anybody??? Quote Link to comment 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.