INNER JOIN Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • exoskeleton
    New Member
    • Sep 2006
    • 104

    INNER JOIN Problem

    hi dear experts im here once again...i have a problem on showing the result when im using inner join...here's my code..

    [PHP]
    $sql_trans_pro_ tbl="SELECT transaction_tbl .date_subscribe ,transaction_tb l.date_expire".
    ",product_tbl.p ro_id,product_t bl.pro_des FROM transaction_tbl INNER JOIN".
    " product_tbl ON transaction_tbl .pro_id=product _tbl.pro_id WHERE".
    " transaction_tbl .account_name=' $forder_name'";
    $update_trans_p ro_tbl=pg_exec( $sql_trans_pro_ tbl);

    while($fld=pg_f etch_array($upd ate_trans_pro_t bl)) {

    $t_date_subscri be=$fld['transaction_tb l.date_subscrib e'];
    $t_date_expire= $fld['transaction_tb l.date_expire'];
    $p_pro_id=$fld['product_tbl.pr o_id'];
    $p_pro_des=$fld['product_tbl.pr o_des'];

    }

    [/PHP]

    i usually do this when im using 1 table only and it works but when i make used of INNER JOIN...nothing happen...please help sir/madam..

    TIA
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    The way you write your query is very confusing.
    I took it a re-aranged it so I could see what you were doing, and there is a weird cap there in your SELECT clause between t1.dat and e_expire.

    Note: I'm not used to Postagre so I wrote this using as common SQL as I could master. Please correct me if I doing something MySQL specific there.
    [PHP]
    $sql_trans_pro_ tbl = "
    SELECT
    t1.date_subscri be,t1.dat e_expire , t2.pro_id, t2.pro_des
    FROM
    transaction_tbl as t1
    INNER JOIN
    product_tbl as t2 ON t1.pro_id = t2.pro_id
    WHERE
    t1.account_name ='$forder_name'
    ";
    [/PHP]

    Aside from that, you use the function pg_exec(). Are you sure you don't mean pg_execute() ? I couldn't find pg_exec() on php.net.

    Comment

    • exoskeleton
      New Member
      • Sep 2006
      • 104

      #3
      hi im sorry..to make you confuse... its date_expire and we're using php 4.4.4 so pg_exec() is ok...

      so it means i have to make use of "as" like you've written?

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        No you can use the full table names if you want.
        I just use it like this so it's easier to read.

        Comment

        • exoskeleton
          New Member
          • Sep 2006
          • 104

          #5
          btw thank you sir

          Comment

          Working...