combined sql queries in PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Julie

    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_caree rs_simple = "SELECT resource.res_id , resource.res_ti tle,
    resource.res_de tails, resource.res_da te_updated,
    resource_isbn.r es_isbn_num,
    resource_date_o f_publish.res_d ate_of_publish, medium.medium_n ame,
    availability.av ail_type, resource_agcas. res_agcas_id,
    agcas.agcas_cla ss, agcas.agcas_nam e, publisher.pub_n ame,
    publisher_detai ls.pub_address, publisher_detai ls.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.r es_id LEFT
    JOIN resource_date_o f_publish ON resource.res_id =
    resource_date_o f_publish.res_i d LEFT JOIN medium ON
    resource.res_me dium_id = medium.medium_i d LEFT JOIN availability ON
    resource.res_av ail_id = availability.av ail_id LEFT JOIN agcas ON
    resource_agcas. res_agcas_id = agcas.agcas_id LEFT JOIN publisher ON
    resource.res_pu b_id = publisher.pub_i d LEFT JOIN publisher_detai ls ON
    publisher_detai ls.pub_id = publisher.pub_i d ";

    $rs_careers_sim ple = mysql_query($bl ah blah or die(mysql_error ());
    $row_rs_careers _simple = mysql_fetch_ass oc($rs_careers_ simple);
    $totalRows_rs_c areers_simple = mysql_num_rows( $rs_careers_sim ple);



    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_interes t ON
    resource_a_o_i_ lkt.aoi_id=area _of_interest.ao i_id";

    $rs_aoi = mysql_query($bl ah blah) or die(mysql_error ());
    $row_rs_aoi = mysql_fetch_ass oc($rs_aoi);
    $totalRows_rs_a oi = mysql_num_rows( $rs_aoi);

  • Jerry Stuckle

    #2
    Re: combined sql queries in PHP

    Julie wrote:[color=blue]
    > 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_caree rs_simple = "SELECT resource.res_id , resource.res_ti tle,
    > resource.res_de tails, resource.res_da te_updated,
    > resource_isbn.r es_isbn_num,
    > resource_date_o f_publish.res_d ate_of_publish, medium.medium_n ame,
    > availability.av ail_type, resource_agcas. res_agcas_id,
    > agcas.agcas_cla ss, agcas.agcas_nam e, publisher.pub_n ame,
    > publisher_detai ls.pub_address, publisher_detai ls.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.r es_id LEFT
    > JOIN resource_date_o f_publish ON resource.res_id =
    > resource_date_o f_publish.res_i d LEFT JOIN medium ON
    > resource.res_me dium_id = medium.medium_i d LEFT JOIN availability ON
    > resource.res_av ail_id = availability.av ail_id LEFT JOIN agcas ON
    > resource_agcas. res_agcas_id = agcas.agcas_id LEFT JOIN publisher ON
    > resource.res_pu b_id = publisher.pub_i d LEFT JOIN publisher_detai ls ON
    > publisher_detai ls.pub_id = publisher.pub_i d ";
    >
    > $rs_careers_sim ple = mysql_query($bl ah blah or die(mysql_error ());
    > $row_rs_careers _simple = mysql_fetch_ass oc($rs_careers_ simple);
    > $totalRows_rs_c areers_simple = mysql_num_rows( $rs_careers_sim ple);
    >
    >
    >
    > 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_interes t ON
    > resource_a_o_i_ lkt.aoi_id=area _of_interest.ao i_id";
    >
    > $rs_aoi = mysql_query($bl ah blah) or die(mysql_error ());
    > $row_rs_aoi = mysql_fetch_ass oc($rs_aoi);
    > $totalRows_rs_a oi = mysql_num_rows( $rs_aoi);
    >[/color]

    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.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    Working...