This topic is locked

Incorrect "where" statement in query for mass email send

10/20/2022 11:47:01 AM
PHPRunner General questions
E
ER1CMURPHY author

Hi all. Hoping for a little assistance... I'm running this script as an "after record updated" event. It's working fine except that it's sending email to the entire database, not just "Administrators." So I suspect my "where" statement is incorrect.
Thank you in advance.


global $dal;
//select emails from Users table
$tblUsers = $dal->Table("Users");
$where {"UserType"}=("Administrator");
$rs = $tblUsers->QueryAll();
while ($data = db_fetch_array($rs))
{
$email=$data["Email"];
$from="myemail@myemail.com";
$msg="A new deal: has been made available!";
$msg.="Deal: ".$values["Business_Name"]."\r\n";
$subject="New Deal Available";
$ret=runner_mail(array('to' => $email, 'subject' => $subject,
'body' => $msg, 'from'=>$from));
if(!$ret["mailed"])
echo $ret["message"]."
";
}


Sergey Kornilov admin 10/20/2022

Eric,

the following is incorrect, you are trying to invent new syntax:
$where {"UserType"}=("Administrator");

Also, DAL is deprecated and we recommend using Database API. Function Select() will do what you need, check the first example.

P
Phil78 10/31/2022

Try using
$rs = $tblUsers->Query("UserType=Administrator");

but DAL is deprecated...