0

我有这个 PHP 代码:

$number = substr_replace($_POST["number"],"44",0,1);

$sql="SELECT * from channel_did where did LIKE '%".$number."%' AND (client_id = '' OR client_id IS NULL or client_id = '611') AND (extension_id = '' OR extension_id IS NULL) ";
$rs=mysql_query($sql,$pbx01_conn) or die(mysql_error());
while($result=mysql_fetch_array($rs))
{
    $numbers_list = $result["did"].'<br>';
    $email_body = '<font face="Arial">
    Hello, here are some numbers that you have requested.<br><br>
    Please be aware that these numbers are in a public pool and not reservered, therefore they could be assigned to another client at any time.<br><br>
    Please make your choice as soon as possible to guarantee the number you require.<br><br>
    '.$numbers_list.'<br><br>
    Kind Regards,<br><br>
    Customer Services<br>
    Integra Digital<br><br>
    tel: 01702 66 77 27<br>
    email: support@domain.co.uk<br>
    web: www.integradigital.co.uk
    </font>';
}

    echo $email_body;

sendemail($_POST["emailto"],"Integra Digital <no-reply@domain.co.uk>","VoIP Phone Numbers You Requested",$email_body,"no-reply@domain.co.uk");

它从表中选择行,我需要它通过电子邮件发送一封包含行列表的电子邮件

当我运行 SQL 时,我知道大约有 10 行(确实)

当它发送电子邮件时,它使用$email_body变量但只在电子邮件中放置一行。

我创建了一个$numbers_list变量,它应该包含所有行的列表,但它只做一行。

4

2 回答 2

6

创建一个数组(),将行数据推送到它..并implode()在 $email_body 中使用;

试试这个

while($result=mysql_fetch_array($rs))
{
    $numbers_list[] = $result["did"];

}

 $email_body = '<font face="Arial">
    Hello, here are some numbers that you have requested.<br><br>
    Please be aware that these numbers are in a public pool and not reserved, therefore they could be assigned to another client at any time.<br><br>
    Please make your choice as soon as possible to guarantee the number you require.<br><br>
    '.implode('<br>',$numbers_list).'<br><br>
    Kind Regards,<br><br>
    Customer Services<br>
    Integra Digital<br><br>
    tel: 01702 66 77 27<br>
    email: support@integradigital.co.uk<br>
    web: www.integradigital.co.uk
    </font>';

和往常一样,不推荐使用 mysql,所以看看 mysqli 或 PDO

于 2013-07-31T12:15:49.493 回答
0
$number_list = Array();
// no need for unneccesary variables
// no need for unneccesary *, SELECT did
$sql="SELECT did from channel_did 
        WHERE       did LIKE '%".substr_replace(mysql_real_escape_string($_POST["number"]),"44",0,1)."%' 
        AND (   client_id = '' 
            OR  client_id IS NULL 
            OR  client_id = '611'
            ) 
        AND (   extension_id = '' 
            OR  extension_id IS NULL
            ) ";
$rs=mysql_query($sql,$pbx01_conn) or die(mysql_error());
while($result=mysql_fetch_array($rs))
{
    $numbers_list[] = $result["did"].'<br>';

}
 $email_body = '<font face="Arial">
    Hello, here are some numbers that you have requested.<br><br>
    Please be aware that these numbers are in a public pool and not reservered, therefore they could be assigned to another client at any time.<br><br>
    Please make your choice as soon as possible to guarantee the number you require.<br><br>
    '.implode(',',$numbers_list).'<br><br>
    Kind Regards,<br><br>
    Customer Services<br>
    Integra Digital<br><br>
    tel: 01702 66 77 27<br>
    email: support@integradigital.co.uk<br>
    web: www.integradigital.co.uk
    </font>';
echo $email_body;
于 2013-07-31T12:17:59.370 回答