具有多行的PHP循环
我有以下PHP代码:具有多行的PHP循环,php,mysql,Php,Mysql,我有以下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=mysq
$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");
$number=substr\u replace($\u POST[“number”],“44”,0,1);
$sql=“选择*从通道_-did,其中像“%”“$number.”“%”和(客户机_-id=''或客户机_-id为NULL或客户机_-id='611')和(扩展名_-id=''或扩展名_-id为NULL)”;
$rs=mysql\u query($sql,$pbx01\u conn)或die(mysql\u error());
而($result=mysql\u fetch\u数组($rs))
{
$numbers_list=$result[“did”]。
;
$email\u body=
您好,这里是您要求的一些号码。
请注意,这些号码位于公共池中,未被保留,因此可以随时分配给其他客户端。
请尽快做出选择,以保证您所需的号码。
“.$numbers\u列表。”
亲切的问候,
客户服务
Integra Digital
电话:01702667727
电邮:support@domain.co.uk
网址:www.integradigital.co.uk
';
}
echo$email_body;
sendemail($_POST[“emailto”],“Integra Digital”,“您请求的VoIP电话号码”,“电子邮件正文”,“否-reply@domain.co.uk");
它从表中选择行,我需要它只发送一封包含行列表的电子邮件
当我运行SQL时,我知道大约有10行(did)
当它发送电子邮件时,它使用$email\u body
变量,但只在电子邮件中放一行
我创建了一个$numbers\u list
变量,该变量应该包含所有行的列表,但它只包含一行。创建一个数组(),将行数据推送到该数组中。。并在$email\u 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>';
while($result=mysql\u fetch\u数组($rs))
{
$numbers_list[]=$result[“did”];
}
$email\u body=
您好,这里是您要求的一些号码。
请注意,这些号码位于公共池中且未保留,因此可以随时分配给其他客户端。
请尽快做出选择,以保证您所需的号码。
“.内爆(“
”,$numbers\u list)。”
亲切的问候,
客户服务
Integra Digital
电话:01702667727
电邮:support@integradigital.co.uk
网址:www.integradigital.co.uk
';
和往常一样,mysql不推荐使用,因此请查看mysqli或PDO创建一个数组(),将行数据推送到其中。。并在$email\u body中使用内爆()
$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;
试试这个
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>';
while($result=mysql\u fetch\u数组($rs))
{
$numbers_list[]=$result[“did”];
}
$email\u body=
您好,这里是您要求的一些号码。
请注意,这些号码位于公共池中且未保留,因此可以随时分配给其他客户端。
请尽快做出选择,以保证您所需的号码。
“.内爆(“
”,$numbers\u list)。”
亲切的问候,
客户服务
Integra Digital
电话:01702667727
电邮:support@integradigital.co.uk
网址:www.integradigital.co.uk
';
而且mysql总是不推荐使用,所以请查看mysqli或PDO$number\u list=Array();
$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;
//不需要不必要的变量
//不需要不必要的*,选择did
$sql=“从频道选择did\u did
像“%”这样的子字符串替换(mysql\u real\u escape\u字符串($\u POST[“number”]),“44”,0,1)在哪里
和(客户id=“”
或客户端id为空
或客户端id='611'
)
和(扩展名_id=“”
或扩展名id为空
) ";
$rs=mysql\u query($sql,$pbx01\u conn)或die(mysql\u error());
而($result=mysql\u fetch\u数组($rs))
{
$numbers_list[]=$result[“did”]。
;
}
$email\u body=
您好,这里是您要求的一些号码。
请注意,这些号码位于公共池中,未被保留,因此可以随时分配给其他客户端。
请尽快做出选择,以保证您所需的号码。
“.内爆(”,“,$numbers\u list)。”
亲切的问候,
客户服务
Integra Digital
电话:01702667727
电邮:support@integradigital.co.uk
网址:www.integradigital.co.uk
';
echo$email_body;
$number\u list=Array();
//不需要不必要的变量
//不需要不必要的*,选择did
$sql=“从频道选择did\u did
像“%”这样的子字符串替换(mysql\u real\u escape\u字符串($\u POST[“number”]),“44”,0,1)在哪里
和(客户id=“”
或客户端id为空
或客户端id='611'
)
和(扩展名_id=“”
或扩展名id为空
) ";
$rs=mysql\u query($sql,$pbx01\u conn)或die(mysql\u error());
而($result=mysql\u fetch\u数组($rs))
{
$numbers_list[]=$result[“did”]。
;
}
$email\u body=
您好,这里是您要求的一些号码。
请注意,这些号码位于公共池中,未被保留,因此可以随时分配给其他客户端。
请尽快做出选择,以保证您所需的号码。
“.内爆(”,“,$numbers\u list)。”
亲切的问候,
客户服务
Integra Digital
电话:01702667727
电邮:support@integradigital.co.uk
网址:www.integradigital.co.uk
';
echo$email_body;
mysql.*
现在已被弃用。请使用或。mysql.*
现在不推荐使用。请使用或。很棒的方法。我会像其他人建议的那样通过连接来实现,但这应该是一个优雅的+1。很棒的方法。我会像其他人所建议的那样通过连接来实现,但这应该得到+1