Hello
I need to send out a reminder e-mail to users that contains information pulled out from the mysql database ......
I am testing this by echoing our the results of the query but I am having problems with the looping of it all.....
The code I have is shown below and the output I am getting is below that in bold.
What I need to stop is the lopping that is causing the MId to repeat itself. I want just the MId for that user and nothing else.
I am also having a problem pulling out the 'special' information from the database but that's another story !
$query = "SELECT CoRef FROM tblDate WHERE FirstRemind = '$today'";
$result30 = mysql_query($query)
or die (mysql_error());
$row30 = mysql_fetch_array($result30);
$Co = $row30["CoRef"];
$query = "SELECT CoName FROM tblCo WHERE CoId = '$Co'";
$result110 = mysql_query($query)
or die(mysql_error());
$row110 = mysql_fetch_array($result110);
$CoName = $row110["CoName"];
$query = "SELECT DateId FROM tblDate WHERE CoRef = '$Co' ORDER BY DateId DESC LIMIT 1";
$result121 = mysql_query($query)
or die(mysql_error());
$row121 = mysql_fetch_array($result121);
$Date = $row121["DateId"];
$query = "SELECT FirstRemind FROM tblDate WHERE DateId = '$Date'";
$result1010 = mysql_query($query)
or die(mysql_error());
$row1010 = mysql_fetch_array($result1010);
$FirstRemind = $row1010["FirstRemind"];
if ($FirstRemind == $today)
{
$query = "SELECT ClientId FROM tblClient WHERE CoRef = '$Co'";
$result119 = mysql_query($query)
or die (mysql_error());
while($row119 = mysql_fetch_array($result119))
$Client[] = $row119["ClientId"];
foreach ($Client as $value)
{
$query = "SELECT CEmail, CName, SRef FROM tblUser
WHERE tblUser.Level >= 3 AND tblUser.ClientRef = '".$value."'";
$result222 = mysql_query($query) or die(mysql_error());
while($row222 = mysql_fetch_array($result222, MYSQL_ASSOC))
{
$Email = $row222["CEmail"];
$UserName = $row222["CName"];
$SRef = $row222["SRef"];
$query = "SELECT SName FROM tblS WHERE SId = '$SRef'";
$result88 = mysql_query($query) or die (mysql_error());
$row88 = mysql_fetch_array($result88);
$SName = $row88["SName"];
$query = "SELECT CoName FROM tblClient WHERE ClientId = '".$value."'";
$result108 = mysql_query($query) or die (mysql_error());
$row108 = mysql_fetch_array($result108);
$ClName = $row108["CoName"];
$sql = "SELECT tblM.MId, tblM.Special, tblS.SId,
tblS.SName, tblClient.ClientId, tblClient.CoName
FROM (tblClient INNER JOIN tblS
ON (tblClient.CoRef = tblS.CoRef)
AND (tblClient.ClientId = tblS.ClientRef))
LEFT JOIN tblM
ON (tblS.CoRef = tblM.CoRef)
AND (tblS.ClientRef = tblM.ClientRef)
AND (tblS.SId = tblM.SRef)
LEFT JOIN tblResults
ON (tblM.CoRef = tblResults.CoRef)
AND (tblM.ClientRef = tblResults.ClientRef)
AND (tblM.SRef = tblResults.SRef)
AND (tblM.MId = tblResults.MRef)
AND tblResults.DateRef = '$Date'
WHERE tblResults.ResultsId Is Null
AND tblM.ClientRef = '".$value."'";
$getinfo = mysql_query($sql) or die (mysql_error());
while($row55 = mysql_fetch_array($getinfo, MYSQL_ASSOC))
$MId[] = $row55["MId"];
$special[] = $row55["Sepcial"];
print_r($UserName); echo'<br>';
print_r($ClName); echo'<br>';
print_r($SRef); echo'<br>';
print_r($SName); echo'<br>';
print_r($Email); echo'<br>';
print_r($special); echo'<br>';
print_r($MId); echo'<br>';
$body2 = "
Hello $UserName of $ClName,
Our records show that you have information still outstanding for the following ;
$special[]
Please log on ........
If you require any assistance please contact us.
Yours sincerely,
$CoName
";
mail ("$Email", "subject", "$body2", "FROM:xxx@xxx.com");
} //close while
} //close foreach
} //close if
Rubber Soles Ticknall Road MId should be 199
Rubber Soles Melbourne Road MIdshould be 200,201
Yellow Submarine London MId should be 310,311
Yellow Submarine Asby MId should be 312
bob builder
Rubber Soles
136
Ticknall Road Office
bob@rs.com
Array ( [0] => )
Array ( [0] => 200 [1] => 201 [2] => 199 )
andy pandy
Rubber Soles
135
Melbourne Road
andy@rs.com
Array ( [0] => [1] => )
Array ( [0] => 200 [1] => 201 [2] => 199 [3] => 200 [4] => 201 [5] => 199 )
fred flintstone
Rubber Soles
136
Ticknall Road Office
fred@rs.com
Array ( [0] => [1] => [2] => )
Array ( [0] => 200 [1] => 201 [2] => 199 [3] => 200 [4] => 201 [5] => 199 [6] => 200 [7] => 201 [8] => 199 )
ringo starr
yellow submarine ltd
224
london business park
ringo@xxx.com
Array ( [0] => [1] => [2] => [3] => )
Array ( [0] => 200 [1] => 201 [2] => 199 [3] => 200 [4] => 201 [5] => 199 [6] => 200 [7] => 201 [8] => 199 [9] => 312 [10] => 311 [11] => 310 )
joe bloggs
yellow submarine ltd
225
ashby business park
joe@xxx.com
Array ( [0] => [1] => [2] => [3] => [4] => )
Array ( [0] => 200 [1] => 201 [2] => 199 [3] => 200 [4] => 201 [5] => 199 [6] => 200 [7] => 201 [8] => 199 [9] => 312 [10] => 311 [11] => 310 [12] => 312 [13] => 311 [14] => 310 )
george harrison
yellow submarine ltd
224
london business park
george@xxx.com
Array ( [0] => [1] => [2] => [3] => [4] => [5] => )
Array ( [0] => 200 [1] => 201 [2] => 199 [3] => 200 [4] => 201 [5] => 199 [6] => 200 [7] => 201 [8] => 199 [9] => 312 [10] => 311 [11] => 310 [12] => 312 [13] => 311 [14] => 310 [15] => 312 [16] => 311 [17] => 310 )