Skip navigation
Currently Being Moderated

Using logged user detail from one table ,then use another table to link more details for same user ?

Feb 17, 2014 2:45 PM

Table 'user' fields:

 

UserID* (Primary Key)

Address

FirstName

LastName

Email

UserName

Password

UserLevel

RegDate

 

 

 

 

Table 'transaction' fields:

 

transactionID* (Primary Key)

MonthID

UserID (Foreign Key)

UserName

transactionDate

transactionType

transactionAmount

OpeningBalance

Balance

 

 

Desired output table (for the logged user):

 

transactionDate

transactionType

transactionAmount

OpeningBalance

Balance

 

 

 

 

 

 

 

 

 

 

My advance recordset details is like this :

 

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

if (PHP_VERSION < 6) {

$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

}

 

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 

switch ($theType) {

case "text":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "long":

case "int":

$theValue = ($theValue != "") ? intval($theValue) : "NULL";

break;

case "double":

$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

break;

case "date":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "defined":

$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

break;

}

return $theValue;

}

}

 

mysql_select_db($database_bankusers, $bankusers);

$query_Recordset1 = "SELECT transactions.UserName, transactions.transactionDate, transactions.transactionType, transactions.transactionAmount, transactions.OpeningBalance, transactions.EndBalance, users.FirstName, transactions.transactionID FROM transactions, users WHERE users.UserName = transactions.UserName ORDER BY transactions.UserName, transactions.transactionID DESC";

$Recordset1 = mysql_query($query_Recordset1, $bankusers) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>

 

This enables me to pull all the records from both tables but not specific to the logged user.

This is my problem. I would like the record to be pull is for the right user.

 

I am not sure if the the problem is to do with Session variable MM_UserName as I have no idea how to include it in the advanced recordset box but i am not sure there is no missing session start on this page.  Your help or suggestion will be much appreciated.

 
Replies
  • Currently Being Moderated
    Feb 17, 2014 3:03 PM   in reply to gurroby

    Try:

     

    $query_Recordset1 = "SELECT transactions.UserName, transactions.transactionDate, transactions.transactionType, transactions.transactionAmount, transactions.OpeningBalance, transactions.EndBalance, users.FirstName, transactions.transactionID FROM transactions, users WHERE users.UserName = transactions.UserName AND users.UserName = $MM_UserName ORDER BY transactions.UserName, transactions.transactionID DESC";

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 17, 2014 3:38 PM   in reply to gurroby

    Sorry, my bad. Try:

     

    $query_Recordset1 = "SELECT transactions.UserName, transactions.transactionDate, transactions.transactionType, transactions.transactionAmount, transactions.OpeningBalance, transactions.EndBalance, users.FirstName, transactions.transactionID FROM transactions, users WHERE users.UserName = transactions.UserName AND users.UserName = $_SESSION['MM_Username']) ORDER BY transactions.UserName, transactions.transactionID DESC";

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 17, 2014 5:17 PM   in reply to gurroby

    No parens around the session variable name:

     

    $query_Recordset1 = "SELECT transactions.UserName, transactions.transactionDate, transactions.transactionType, transactions.transactionAmount, transactions.OpeningBalance, transactions.EndBalance, users.FirstName, transactions.transactionID FROM transactions, users WHERE users.UserName = transactions.UserName AND users.UserName = $_SESSION['MM_Username'] ORDER BY transactions.UserName, transactions.transactionID DESC";

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points