2013-08-17 69 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