2013-08-17 66 views
0

即时尝试生成一个电子邮件,以包括一些排序的数据在正文中。 我的电子邮件发送但没有正文中的数据。通过函数也是while循环,如果有意义的话,它们会生成回显的html内容? 这里是其中的一个功能。在字符串中的while循环中运行一个函数?

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>";}} 

,这就是我称之为

$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>"; 

没有,如果我改变函数返回一个值,而不是呼应的,我得到的结果,而不是完整循环的只是第一行,但就是包括在电子邮件正文文本中,并且当我在脚本结尾处使用echo函数调用函数时,我会得到所需的输出。 有什么办法可以让这个工作?在此先感谢尼克

+0

你试过一个“沙箱”来回显$ inouty?还单独$ inouty并从那里工作... – Pogrindis

回答

0

由于您的通话尝试包括该功能的结果,你只需要确保你返回所有沿途产生的线。有很多方法可以做到这一点,这里有一个:

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()); 

    $result = ""; 

    while ($row = mysql_fetch_assoc($inouty)) { 
    $sname = htmlspecialchars($row['sname']); 
    $in = htmlspecialchars($row['con']); 
    $out = "- ". htmlspecialchars($row['coff']); 

    $result .= "$sname $in $out<br>"; 
    } 

    return $result; 
} 
+0

这就是它,大声笑只有在这样的4小时:-(感谢您的帮助表示赞赏。 – Nick