This topic is locked

How to show all records from database in an email?

12/9/2012 9:06:52 PM
PHPRunner General questions
P
phpcmk author

Hi,
I have a database containing 2 tables ("table1" and "table2").
table1: containing 4 fields ("id", "name", "field1", "field2")

table2: containing 2 fields ("id", "name")
"id" is the primary key and auto-increment

"name" is assigned with unique key
Below are my codes:

--------------------------

After record added in table1
global $dal;

if ($values["field1"]=="Yes" && $values["field2"]=="Yes"){

$dal_table = $dal->Table("table2");

$dal_table->name=$values["name"];

$dal_table->Add();
/The below code is my mail function, however this will only send an email containing the new record/

include "include_mail.php";

mysendmail ("email address","title",$values["name"]);

}
The above code will always create a new name in table2 whenever the if statement met.
My question is how can I send 1 email that contains all the available records(name) from table2? In other words, whenever new records created in table2, user will recieve an email with the new created "name" and previous created "name".
Thanks in advance for the help.

P
phpcmk author 12/9/2012

Hi,
Just figure out how to show all records in an email after record added:

---------------------

After record added
if ($values["field1"]=="Yes" && $values["field2"]=="Yes"){
include "include_mail.php";
mysql_connect ("localhost", "username", "password") or die (mysql_error());

mysql_select_db ("database") or die (mysql_error());
$result=mysql_query("SELECT * FROM table_name");
while ($row=mysql_fetch_array($result)){

$message.= $row["id"] . ". " . $row["name"] . "<p>";

}

mysendmail("xxxxx@xxx.com", "title", $message);

}

------------------------------------------
Now, I would like to send an email with updated records whereby email will be sent only if a user deleted a record with field1=Yes and field2=Yes.
I have no idea where should i place the code in phprunner. I have tried using the same above code and put it in After record deleted but it is not working.
Thanks in advance for the help.