This topic is locked

Multiple table data in email

12/6/2020 4:32:18 PM
PHPRunner General questions
D
david22585 author

So I have a form where a logged in user submits some data. I'm trying to use one $_SESSION variable to query an array of data to use in the email. For example, the SESSION data has their account number in it. Using that, I can reference 2 other tables that have the account_id in it for other data, such as address in 1 table, and contact information and name in another table. I tried the following 2 codes without success. Each one will echo the data in a code snippet, but will not show the data in the email:
The first one I tried to store the data in a SESSION, reference the SESSION in the email, and unset the session at the end with it not working:

$rs = DB::Query("SELECT account_data.ownername, account_data.email, account_data.phone, unit_data.address FROM account_data

LEFT OUTER JOIN unit_data ON account_data.address = unit_data.unit WHERE account_data.id = '".$_SESSION["account_id"]."'");

while( $data = $rs->fetchAssoc()){
$data["address"] = $_SESSION["mailaddress"];

$data["ownername"] = $_SESSION["ownername"];

$data["email"] = $_SESSION["email"];

$data["phone"] = $_SESSION["phone"];

}


That didn't work, so I went to the next option, DBLookup:

$data = DBLookup("SELECT account_data.ownername, account_data.email, account_data.phone, unit_data.address FROM account_data

LEFT OUTER JOIN unit_data ON account_data.address = unit_data.unit WHERE account_data.id = '".$_SESSION["account_id"]."'");


Then I tried to reference $data["fieldvalue'] within the email, and it was still blank.
The only way I was able to get it to work was to create individual DBLookup's, but I would prefer to have 1 instead of multiple lookups to reduce the load on the server. This is what I have that works right now:



$name = DBLookup("SELECT displayname FROM website_users WHERE id = ".$_SESSION["user_id"]."");

$phone = DBLookup("SELECT phone FROM account_data WHERE id = ".$_SESSION["account_id"]."");

$addresa = DBLookup("SELECT address FROM unit_data WHERE account_id = ".$_SESSION["account_id"]."");

$sendemail = DBLookup("SELECT email FROM website_users WHERE id = ".$_SESSION["user_id"]."");


I was wondering if there were any other options to make it into 1 query instead of 4.

Sergey Kornilov admin 12/7/2020

Your first code example is meaningless and it is hard to understand what you tried to do there. You are saying that "I tried to store the data in a SESSION" but in fact, you are doing the opposite, you are overwriting the values from the data with session variables.
In programming the variable you assigning the value to goes on the left side i.e.

$variable = "some value";