Jump to content

Show an ID from 2 tables


chuck808

Recommended Posts

Hi,

 

I hope I'm not about to offend anyone by posting this in the wrong place.

 

V 5.1.56

 

I have a PHP SQL query/function that returns two users details based on a transaction Id from a transaction table and it works fine. However, in the returned result I would also like to show the Transaction Id and for the life of me I can't get it to work.

 

This is the code showing one users details and the returned details below.

 

$sql = "SELECT * from " . TABLEPREFIX . "transactiontxn where nSTId='" . $_REQUEST['nSTId'] . "'";
$res = mysql_query($sql) or die(mysql_error());
if ($srow = mysql_fetch_array($res)){
    if ($srow['nUserId']==$_SESSION['guserid']) {
        $this_user = $srow['nUserId'];
        $other_user = $srow['nUserReturnId'];
    }
}//end if


if ($var_mode == "A" && $var_flag = "true") {

    $sql = "SELECT vLoginName,vFirstName,vLastName,vAddress1,vAddress2,vCity,vState,
             vCountry,nZip,vPhone,vFax,vEmail FROM
             " . TABLEPREFIX . "users U where nUserId='" . $this_user . "' ";

    $result = mysql_query($sql) or die(mysql_error());
    if (mysql_num_rows($result) > 0) {
        if ($row = mysql_fetch_array($result)) {
            $var_login2 = stripslashes($row["vLoginName"]);
            $var_first2 = stripslashes($row["vFirstName"]);
            $var_last2 = stripslashes($row["vLastName"]);
            $var_address12 = stripslashes($row["vAddress1"]);
            $var_address22 = stripslashes($row["vAddress2"]);
            $var_city2 = stripslashes($row["vCity"]);
            $var_state2 = stripslashes($row["vState"]);
            $var_country2 = stripslashes($row["vCountry"]);
            $var_zip2 = stripslashes($row["nZip"]);
            $var_phone2 = stripslashes($row["vPhone"]);
            $var_fax2 = stripslashes($row["vFax"]);
            $var_email2 = stripslashes($row["vEmail"]);
		$var_transactionid = stripslashes($row["nTransactionId"]);
        }//end if
    }//end if
    $message = TEXT_DETAILS_OF_COMMUNITATION_GIVEN_BELOW;
    $var_form = "A";
}//end if
else if ($var_mode == "R" && $var_flag = "true") {
    $message2 = TEXT_OFFER_REJECTED;
    $var_form = "R";
}//end else if

 

What is returned;

 

Full Name         user name

Address Line 1 user address

Address Line 2 user address

City                 user address

State               user address

Country           user address

Zip                   user address

Phone             user number

Fax                   user fax

Email               user email

Transaction ID         

        The Transaction isn't currently showing

 

Any help would be appreciated

 

Link to comment
Share on other sites

  The Transaction isn't currently showing

 

$var_transactionid = stripslashes($row["nTransactionId"]);

 

where in your SELECT are you getting the nTransactionId column (assuming that the column exists in your table users)?

 

    $sql = "SELECT vLoginName,vFirstName,vLastName,vAddress1,vAddress2,vCity,vState,
             vCountry,nZip,vPhone,vFax,vEmail FROM
             " . TABLEPREFIX . "users U where nUserId='" . $this_user . "' ";

 

Link to comment
Share on other sites

Hi mikosiko,

 

Thanks for the reply. I have realised how thick I am, nTransactionId column is from

 

$sql = "SELECT * from " . TABLEPREFIX . "transactiontxn where nSTId='" . $_REQUEST['nSTId'] . "'";
$res = mysql_query($sql) or die(mysql_error());
if ($srow = mysql_fetch_array($res)){
    if ($srow['nUserId']==$_SESSION['guserid']) {
        $this_user = $srow['nUserId'];
        $other_user = $srow['nUserReturnId'];
    }
}//end if

 

I think  :-[ I want to be able to show the transaction ID nSTID?

 

Sorry for being so dense

 

Link to comment
Share on other sites

you are the only one that could know how your transaction id field is called... either way.. assuming (for you to check) that your field name is nSTId you can assign it value to some variable here:

        $this_user = $srow['nUserId'];
        $other_user = $srow['nUserReturnId'];
        $transactionId = $row['nSTId'];

 

and use $transactionId in the rest of your code

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.