Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何内爆记录集列?_Php_Arrays_Email_Recordset_Implode - Fatal编程技术网

Php 如何内爆记录集列?

Php 如何内爆记录集列?,php,arrays,email,recordset,implode,Php,Arrays,Email,Recordset,Implode,我试图发送一封电子邮件到多个电子邮件地址,这些地址包含在一个数据库中,并排序到一个记录集。。。记录集有多个列,但我只需要一个:Email。我知道如果把它们放在一个数组中,我可以将它们内爆并用逗号分隔,但我不确定如何使用记录集列来实现这一点。有人知道怎么做吗 以下是记录集代码: 新代码: 你需要自己粘上去。内爆在这里是没有用的,因为您必须遍历您的记录集,提取电子邮件,放入单独的数组,然后内爆。但由于您已经在进行迭代,因此可以使用临时数组粘合它并进行内爆,如下所示: $glued = ""; $se

我试图发送一封电子邮件到多个电子邮件地址,这些地址包含在一个数据库中,并排序到一个记录集。。。记录集有多个列,但我只需要一个:Email。我知道如果把它们放在一个数组中,我可以将它们内爆并用逗号分隔,但我不确定如何使用记录集列来实现这一点。有人知道怎么做吗

以下是记录集代码:

新代码:


你需要自己粘上去。内爆在这里是没有用的,因为您必须遍历您的记录集,提取电子邮件,放入单独的数组,然后内爆。但由于您已经在进行迭代,因此可以使用临时数组粘合它并进行内爆,如下所示:

$glued = "";
$separator = "";
foreach( $row_rsAllLEads as $row ) {
   $glued .= $separator . $row['Email'];
   $separator = ", ";
}
编辑1

您的代码也需要修复,因为您只获取第一行集,而不是所有匹配where子句的行集。它应该是这样的,您应该将变量名从行更改为。。。到…去。。。也是:


因此,毕竟$row\u rsAllLeads应该是数组的数组。

好的,我该如何使用它?我是否将$row_rsAllLeads['Email']放在电子邮件功能的$to部分?那么它是否已经格式化了呢?这取决于您发送邮件的方式,但通常是这样,这应该足够了,因为它是有效的电子邮件分隔符。但是我强烈建议不要使用TO:但是BCC:否则你会将所有电子邮件透露给每个收件人。这太糟糕了。我尝试回显$row_rsAllLeads['Email'],结果只显示了一封电子邮件/现在它返回空值。。。请查看我上面的代码并告诉我我做错了什么好吗您必须删除$row\u rsAllLeads=mysql\u fetch\u assoc$rsAllLeads;因为你浪费了第一个匹配的行
$colname_rsAllLeads = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rsAllLeads = $_SESSION['MM_Username'];
}
mysql_select_db($database_myBackOfficeConn, $myBackOfficeConn);
$query_rsAllLeads = sprintf("SELECT Email FROM Leads WHERE `User` = %s ORDER BY FullName ASC", GetSQLValueString($colname_rsAllLeads, "text"));
$rsAllLeads = mysql_query($query_rsAllLeads, $myBackOfficeConn) or die(mysql_error());
$row_rsAllLeads = mysql_fetch_assoc($rsAllLeads);
$totalRows_rsAllLeads = mysql_num_rows($rsAllLeads);

$row_rsAllLeads = array();
while( $row = mysql_fetch_assoc($rsAllLeads) ) {
   $row_rsAllLeads[] = $row;
}

$glued = "";
$separator = "";
foreach( $row_rsAllLeads as $row ) {
   $glued .= $separator . $row['Email'];
   $separator = ", ";
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
} 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {

    $startcode = $_POST['messagefield'];
    $replaced = preg_replace( '/\\\\(?="|\')/', '', $startcode );
    echo $replaced;
    $collectedleads = $row_rsAllLeads['Email'];
    echo $collectedleads;

    /*
 $to = $collectedleads;
 $subject = $_POST['subjectfield'];
 $body = $replaced;
 $headers = "MIME-Version: 1.0\r\n"; 
 $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
 $headers .= "From: " . $row_rs_CurrentUser['FirstName'] . " " . $row_rs_CurrentUser['LastName'] . " <" . $row_rs_CurrentUser['Email'] . ">";
 if (mail($to, $subject, $body, $headers)) {
  } else {
   echo("<p>Message delivery failed...</p>");
  }
  */

  $insertSQL = sprintf("INSERT INTO PendingEmails (`to`, subject, message) VALUES (%s, %s, %s)",
                       GetSQLValueString($row_rsAllLeads['Email'], "text"),
                       GetSQLValueString($_POST['subjectfield'], "text"),
                       GetSQLValueString($_POST['messagefield'], "text"));

  mysql_select_db($database_myBackOfficeConn, $myBackOfficeConn);
  $Result1 = mysql_query($insertSQL, $myBackOfficeConn) or die(mysql_error());

  $insertGoTo = "Email Sent.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
$glued = "";
$separator = "";
foreach( $row_rsAllLEads as $row ) {
   $glued .= $separator . $row['Email'];
   $separator = ", ";
}
$row_rsAllLeads = array();
while( $row = mysql_fetch_assoc($rsAllLeads) ) {
   $row_rsAllLeads[] = $row;
}