MySQL Forums
Forum List  »  PHP

dependent queries on one page?
Posted by: Christopher Adams
Date: April 10, 2007 10:00AM

I apologize if I have posted this question before, but I can't find my previous message if I did.

I have a page that has an address something like:

http://someserver.com/subject.php?SID=23


SID is the 'SID' field of the 'subject' table in 'database1'. I do a query on the subject database using the SID from the URL.

Within the subject.php page, I want to do a MYSQL query of 'database2' and display some of the data from it. One of the fields is 'CID' in the 'category' table. I don't want to include any data from 'database1' in this query, but since database1.subject.SID is equal to database2.category.CID, I figure I can use it to identify the 'category' in 'database2'. See Query 2 below. I realize that the problem is the 'WHERE c.CID=" . $_GET['SID'] . I don't know how to pull in the SID value from the URL to use in Query 2.

In the first query, I did this:

Query 1 (database1: tables- subject)



mysql_select_db("database1")or die("Could not connect : " . mysql_error());
$qry1 = "SELECT SID from subject";
$results = mysql_query($qry1) or die("Query failed : " . mysql_error());
$SID = $_GET['SID'];

Query 2:

database2 (tables: item, bridge, category)

mysql_select_db("database2")or die("Could not connect : " . mysql_error());
$qry = "SELECT title,url from item i left join bridge b on i.ID=b.ID left join category c on b.CID=c.CID WHERE c.CID=" . $_GET['SID'] . "order by title";

I hope that is clear enough and that someone can give me some tips on how to do this. It is unclear to me what I can use from previous queries if I have multiple queries on a page. Thanks.

Options: ReplyQuote


Subject
Written By
Posted
dependent queries on one page?
April 10, 2007 10:00AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.