0

我有这段代码可以连接到 mysql 并从一个表中获取数据:

<?php

    //Include database connection details
    require_once('sql/config.php');

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }

    $result = mysql_query("SELECT * FROM customers");

    while($row = mysql_fetch_array($result)) {
        echo $row['email'];
        echo "<br />";
    }

    mysql_close($link);
?>

现在我怎样才能将这个电子邮件数据从 mysql 填充到以前安全地创建的表单中?

4

1 回答 1

0

改变

while($row = mysql_fetch_array($result)) {
        echo $row['email'];
        echo "<br />";
    }

到:

while($row = mysql_fetch_array($result)) {
        $emails_array[] = $row['email'];
    }

然后$emails_array用作:

$people_to_email_to = implode(";", $emails_array);

然后你的表格:

echo "<input id='emails' type='text' value='$people_to_email_to' name='emails' />";
于 2012-04-12T13:13:03.623 回答