Friday, 16 August 2013

Run a function inside a while loop inside a string?

Run a function inside a while loop inside a string?

im trying to generate an email to include some sorted data in the body. My
email sends but does not have the data in the body from the functions. by
functions are also while loops and they generate echoed html content if
that makes sense? here is one of the functions.
function ye($coid){
$yest = date("Y-m-d", time() - 86400);
$inouty= mysql_query("SELECT clockings.id AS cid,clockings.uid,
clockings.con, clockings.coff, staff.sname ,staff.id, staff.act,
staff.coid FROM clockings LEFT JOIN staff ON clockings.uid=staff.id WHERE
clockings.dte = '$yest' AND staff.coid =$coid ORDER BY staff.id,
clockings.id")or die(mysql_error());
while ($row = mysql_fetch_assoc($inouty)) {
$sname= $row['sname'];
$in= $row['con'];
$out= "- ". $row['coff'];
$id = $row['cid'];
echo"$sname $in $out<br>";}}
and this is where i call it
$html_text = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01
Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<head>
<meta http-equiv='Content-Type'
content='text/html; charset=utf-8'>
<title>Email</title>
</head>
<body>details Current status for $nicedate as of
$now<br>". tod($coid)."<br>Yesterdays Clockings<br>".
ye($coid)."</body>
</html>";
No if I change the function to return a value instead of echoing i get
just the first row of results instead of the full loop but that is
included in the email body text and also when i call the function at the
end of the script using echo in my function i get the desired output. Is
there any way i can get this to work? Thanks in advance Nick

No comments:

Post a Comment