Hi,
I have the following code which produces a page which lists the differences between two tables. It outputs correctly (although as a newbie, the code is very very messy):
//query to compare translations from two tables
$compare_translations = "select $table2.Project, $table2.Notes, $table2.Name FROM $table2 LEFT JOIN $table ON $table2.Name=$table.Name WHERE $table.Name IS NULL AND $table2.Task_type='translations'";
//executes query
if (!($connection = @ mysql_connect($hostName, $username, $password)))
die("Could not connect to database");
if (!mysql_select_db($databaseName, $connection))
showerror();
if (!($translations_result = @ mysql_query ($compare_translations, $connection)))
showerror();
//Displays Translation changes
$trans = @ mysql_fetch_array($translations_result);
$trans = $trans["Name"];
if (!empty($trans))
{
mysql_data_seek($translations_result, 0);
echo "The <b>TRANSLATIONS </b>for the following projects have beed added/edited:<br>";
$value = ' ';
while ($translations = @ mysql_fetch_array($translations_result))
{
if ($value != $translations["Project"])
{
echo "- ".$translations["Project"]."<br>";
$value = $translations["Project"];
}
}
echo "<br>The additions/changes are as follows:<br>";
$value = ' ';
mysql_data_seek($translations_result, 0);
while ($translations = @ mysql_fetch_array($translations_result))
{
if ($value != $translations["Project"])
{
echo "<b><br><u>Project: ".$translations["Project"]."</u></b><br>";
$value = $translations["Project"];
}
//if ($translations["Notes"] != null)
if(!empty($translations["Notes"]))
{
echo "<br><b><i>".$translations["Notes"]."</i></b><br>";
}
echo $translations["Name"]."<br>";
}
echo "<br><hr><br>";
}
However, instead of outputing onto a page which it currently does, I want the output to be within an email.
I know when sending an email you can assign the body of the mail as e.g. $message. so therefore, I could replace echos with a variable and then concatenate them like $message.$message1 etc., however, as the while statment produces alist, this does not work as it only gives you one value, i.e the last in the loop:
//query to compare translations from two tables
$compare_translations = "select $table2.Project, $table2.Notes, $table2.Name FROM $table2 LEFT JOIN $table ON $table2.Name=$table.Name WHERE $table.Name IS NULL AND $table2.Task_type='translations'";
//executes query
if (!($connection = @ mysql_connect($hostName, $username, $password)))
die("Could not connect to database");
if (!mysql_select_db($databaseName, $connection))
showerror();
if (!($translations_result = @ mysql_query ($compare_translations, $connection)))
showerror();
//Displays Translation changes
$trans = @ mysql_fetch_array($translations_result);
$trans = $trans["Name"];
if (!empty($trans))
{
mysql_data_seek($translations_result, 0);
$message = "The <b>TRANSLATIONS </b>for the following projects have beed added/edited:<br>";
$value = ' ';
while ($translations = @ mysql_fetch_array($translations_result))
{
if ($value != $translations["Project"])
{
$message1 = "- ".$translations["Project"]."<br>";
$value = $translations["Project"];
}
}
$message2 = "<br>The additions/changes are as follows:<br>";
$value = ' ';
mysql_data_seek($translations_result, 0);
while ($translations = @ mysql_fetch_array($translations_result))
{
if ($value != $translations["Project"])
{
echo "<b><br><u>Project: ".$translations["Project"]."</u></b><br>";
$value = $translations["Project"];
}
//if ($translations["Notes"] != null)
if(!empty($translations["Notes"]))
{
$message3 = "<br><b><i>".$translations["Notes"]."</i></b><br>";
}
$message4 = $translations["Name"]."<br>";
}
echo "<br><hr><br>";
}
I have searched the web for days looking for an answer and I am none the wiser, if anyone can help I would very much appreciate it as I am starting to have sleepless nights!!
Thanks