This topic is locked
[SOLVED]

How do I modify this code?

4/2/2022 8:38:08 AM
PHPRunner General questions
J
Jan author

Hello everyone,

I have built a member program with phprunner. I want to add a mail function, to send the members an email. I do that with this code:

global $dal;
//select emails from Users table
$tblUsers = $dal->Table("members");
$rs = $tblUsers->QueryAll();
while ($data = db_fetch_array($rs))
{
$email=$data["Email"];
$from="my@test.com";
$msg="This is a test";
$subject="Monthly newsletter";
$ret=runner_mail(array('to' => $email, 'subject' => $subject,
'body' => $msg, 'from'=>$from));
if(!$ret["mailed"])
echo $ret["message"]."
";
}

But sometimes I only want to send an email to a part of the member table, eg by making a query. How should the code be modified? thanks.

J
jacktonghkDevClub member 4/3/2022

I found in the HELP that you can use Query(where, orderby) instead of QueryAll()

e.g. $rs = $tblUsers->Query("Name like '%Jim%'","Email DESC");

J
Jan author 4/4/2022

That's the solution. Thank you.