This topic is locked

Select email from another table

7/18/2019 10:14:35 AM
PHPRunner General questions
H
harveyspecter author

Hello, I used that code for daily expired jobs mails and its awesome. However,
I need it to mail to person who is responsible of the job.
So in the "TableName" table i have a field called "resposible_id" and that ID is the ID of user in "UserTable" table.
Also "UserTable" has "email" field.
I need it to email to that person?
How can i do it?
Thanks alot!

<?php

include("include/dbcommon.php");

global $dal;

$dalTableName = $dal->Table("TableName");

$rstmp = $dalTableName->Query("DateDiff(now(),ExpiryDate)>0","");;

while ($datatmp = db_fetch_array($rstmp))

{

//send email for each record

$email="blabla@test.com";

//EmailField is your actual field name

$msg="This event was expired\r\n";

$msg.="FieldName1: ".$datatmp["FieldName1"]."\r\n";

$msg.="FieldName2: ".$datatmp["FieldName2"]."\r\n";

$subject="Expired";

runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg));

}

//FieldName1, FieldName2 and ExpiryDate are your actual field names, TableName is your actual table name

?>
admin 7/18/2019

To retrieve data from another table you can use Database API:

https://xlinesoft.com/phprunner/docs/about_database_api.htm
If you only need to retrieve a single field value like email address DBLookup function offers a nice shortcut:

https://xlinesoft.com/phprunner/docs/dblookup.htm