我有这个 PHP 代码:
for($i=1; $i<=$_POST["counter"]; $i++)
{
if($_POST["checkbox$i"])
{
//select the billing_pdf row
$sql="SELECT * from billing_pdf_archive where sequence = '".$_POST["checkbox$i"]."' ";
$rs=mysql_query($sql,$conn);
while($result=mysql_fetch_array($rs))
{
//now select all contacts for the company who receive all accounts emails
$sql2="SELECT * from contacts where company_sequence = '".$result["customer_sequence"]."' and receive_accountsemails = 'yes' ";
$rs2=mysql_query($sql2,$conn) or die(mysql_error());
if(mysql_num_rows($rs2) > 0)
{
while($contacts2=mysql_fetch_array($rs2))
{
//generate the list of emails address in an array
$emails_list[] = $contacts2["email"];
}
$emails_list = implode(',',$emails_list);
}
}
$ins_sql2="INSERT into email_attachments (email_seq, attachment) values ('".$email_sequence."', '".$result["pdf"]."') ";
$ins_rs2=mysql_query($ins_sql2,$conn) or die(mysql_error());
$up_sql="UPDATE emails set emailto = '".$emails_list."' where sequence = '".$email_sequence."' ";
$up_rs=mysql_query($up_sql,$conn);
}
}
但我收到此错误:
致命错误:[] 运算符不支持字符串
线上写着:
$emails_list[] = $contacts2["email"];
我在其他页面上使用相同的数组代码(没有 for 循环)并且它们工作正常
我究竟做错了什么?
你填充数组$emails_list[]
在第二次与$contacts2["email"]
。
在下一行中,将数组内爆为字符串。
下一个结果(第一个 while 循环)$emails_list
是一个字符串。现在你不能将字符串转换为数组
尝试这个:
$emailsListData = array();
while($contacts2=mysql_fetch_array($rs2))
{
//generate the list of emails address in an array
$emailsListData[] = $contacts2["email"];
}
$emails_list = implode(',',$emailsListData);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)