473,378 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

combined sql queries in PHP

Hi, I was wondering if anyone could help me, im having abit of a prob
combining these two queries to get the result i want. The queries both
work perfectly, but i need to somehow put the second query into the
first one so that after the first one runs it will run the second one
and then return out these records. I know this is a sql thing, but i
thought since i was doing it in PHP there may be a nice way of doing it
instead of using sql, which isnt as flexible :) I know these are looong
queries, but id be grateful if someone took the time to have a peek!
the fact i have quite a few joins doesnt seem to be helping me when i
try and work it out - Doh!!

Thanks in advance :D
Julie

First query (main query)

mysql_select_db($blah, blah....);

$query_rs_careers_simple = "SELECT resource.res_id, resource.res_title,
resource.res_details, resource.res_date_updated,
resource_isbn.res_isbn_num,
resource_date_of_publish.res_date_of_publish, medium.medium_name,
availability.avail_type, resource_agcas.res_agcas_id,
agcas.agcas_class, agcas.agcas_name, publisher.pub_name,
publisher_details.pub_address, publisher_details.pub_tlf FROM resource
LEFT JOIN resource_agcas ON resource.res_id = resource_agcas.res_id
LEFT JOIN resource_isbn ON resource.res_id = resource_isbn.res_id LEFT
JOIN resource_date_of_publish ON resource.res_id =
resource_date_of_publish.res_id LEFT JOIN medium ON
resource.res_medium_id = medium.medium_id LEFT JOIN availability ON
resource.res_avail_id = availability.avail_id LEFT JOIN agcas ON
resource_agcas.res_agcas_id = agcas.agcas_id LEFT JOIN publisher ON
resource.res_pub_id = publisher.pub_id LEFT JOIN publisher_details ON
publisher_details.pub_id = publisher.pub_id ";

$rs_careers_simple = mysql_query($blah blah or die(mysql_error());
$row_rs_careers_simple = mysql_fetch_assoc($rs_careers_simple);
$totalRows_rs_careers_simple = mysql_num_rows($rs_careers_simple);

second query (sub query... i think!)

mysql_select_db($blah, blah);
$query_rs_aoi = "SELECT res_id, aoi_name FROM resource_a_o_i_lkt INNER
JOIN area_of_interest ON
resource_a_o_i_lkt.aoi_id=area_of_interest.aoi_id" ;

$rs_aoi = mysql_query($blah blah) or die(mysql_error());
$row_rs_aoi = mysql_fetch_assoc($rs_aoi);
$totalRows_rs_aoi = mysql_num_rows($rs_aoi);

Jan 22 '06 #1
1 1359
Julie wrote:
Hi, I was wondering if anyone could help me, im having abit of a prob
combining these two queries to get the result i want. The queries both
work perfectly, but i need to somehow put the second query into the
first one so that after the first one runs it will run the second one
and then return out these records. I know this is a sql thing, but i
thought since i was doing it in PHP there may be a nice way of doing it
instead of using sql, which isnt as flexible :) I know these are looong
queries, but id be grateful if someone took the time to have a peek!
the fact i have quite a few joins doesnt seem to be helping me when i
try and work it out - Doh!!

Thanks in advance :D
Julie

First query (main query)

mysql_select_db($blah, blah....);

$query_rs_careers_simple = "SELECT resource.res_id, resource.res_title,
resource.res_details, resource.res_date_updated,
resource_isbn.res_isbn_num,
resource_date_of_publish.res_date_of_publish, medium.medium_name,
availability.avail_type, resource_agcas.res_agcas_id,
agcas.agcas_class, agcas.agcas_name, publisher.pub_name,
publisher_details.pub_address, publisher_details.pub_tlf FROM resource
LEFT JOIN resource_agcas ON resource.res_id = resource_agcas.res_id
LEFT JOIN resource_isbn ON resource.res_id = resource_isbn.res_id LEFT
JOIN resource_date_of_publish ON resource.res_id =
resource_date_of_publish.res_id LEFT JOIN medium ON
resource.res_medium_id = medium.medium_id LEFT JOIN availability ON
resource.res_avail_id = availability.avail_id LEFT JOIN agcas ON
resource_agcas.res_agcas_id = agcas.agcas_id LEFT JOIN publisher ON
resource.res_pub_id = publisher.pub_id LEFT JOIN publisher_details ON
publisher_details.pub_id = publisher.pub_id ";

$rs_careers_simple = mysql_query($blah blah or die(mysql_error());
$row_rs_careers_simple = mysql_fetch_assoc($rs_careers_simple);
$totalRows_rs_careers_simple = mysql_num_rows($rs_careers_simple);

second query (sub query... i think!)

mysql_select_db($blah, blah);
$query_rs_aoi = "SELECT res_id, aoi_name FROM resource_a_o_i_lkt INNER
JOIN area_of_interest ON
resource_a_o_i_lkt.aoi_id=area_of_interest.aoi_id" ;

$rs_aoi = mysql_query($blah blah) or die(mysql_error());
$row_rs_aoi = mysql_fetch_assoc($rs_aoi);
$totalRows_rs_aoi = mysql_num_rows($rs_aoi);


I'd suggest you ask in comp.databases.mysql.

I think there's a SQL only answer to your problem - but I'm not sure.
I'd need your MysQL version, table layout and what you're actually
trying to achieve.

Just posting SQL statements doesn't help much.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
2
by: clintonG | last post by:
Is there a document that explains the difference between the Visual Studio .NET 2003 Combined Help Collection and the MSDN Library for Visual Studio .NET 2003 or does someone have comments...
1
by: Roger Green | last post by:
I have inherited a complex database that has many dozens of queries that derive data from a people table. I now need to be able to run these queries (from within a significant number of forms)...
3
by: NeilAnderson | last post by:
I'm a fairly new user of access & I've never had any training, so I'm wondering if I'm doing the right thing here, or if it matter at all. I'm building a database for room booking purposes and I'm...
5
by: Jerry Hull | last post by:
I'm working with a database developed by an untrained person over several years - and on a network that has recently been upgraded with a new server installed and MS office upgraded from 2K (I...
1
by: Riley DeWiley | last post by:
I have an application with two tables, A and B. Each has an autonumber unique ID field, plus other data. I have a junction table, AB, containing fields AID, BID, and Count (a number). AB has...
9
by: Fish Womper | last post by:
I am at best a part time developer of Access databases. I use Access 2.0, as this is all my employer has on its computers. Even so, to use this ancient version requires a fairly convoluted...
4
by: Gary Wessle | last post by:
Hi is there a module to do things like concatenate all files in a given directory into a big file, where all the files have the same data formate? name address phone_no. or do I have to open...
8
by: Elfae | last post by:
I have searched high and low for a sample for this, and I just can't find any. Sorry for the length! Background Information The issue revolves around setting up a system-generated increase in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.