gpt4 book ai didi

php - 如何在一个具有不同ID的字段中插入多个文本框值?

转载 作者:行者123 更新时间:2023-11-29 21:33:28 24 4
gpt4 key购买 nike

这是我的代码。它仅插入最后一个元素值。我想将所有值插入具有不同 id 的一个字段中,并将所有数据插入不同的不同行中。

    public function update($user_slider, $user_welcomebox, $user_servicebox, $user_postbox, $user_testimonials, $user_welcomemessage, $user_welcomededcription, $user_welcomelink, $user_welcomelinktitle, $user_servicetitle, $user_totalservicedisplay, $user_ourservice, $user_blogtitle, $user_totalblogdisplay,$user_ourblog, $user_newstitle, $user_totalnewsdisplay, $user_ournews, $user_totaltestimonialdisplay, $user_ourtestimonial) {
$db = connectionstart();
$currentdatetime = date("Y-m-d H:i:s", time());
$currentgmtdatetime = gmdate("Y-m-d H:i:s", time() - (5 * 60 * 60));
$sql = "select * from user_options ";
$result = mysql_evaluate($db, $sql, 0);
$columns = array(
"name" => 'slider'
, "value" => $user_slider
,"name" => 'welcomebox'
, "value" => $user_welcomebox
,"name" => 'servicebox'
, "value" => $user_servicebox
,"name" => 'postbox'
, "value" => $user_postbox
,"name" => 'testimonials'
, "value" => $user_testimonials
,"name" => 'welcomemessage'
, "value" => $user_welcomemessage
,"name" => 'welcomededcription'
, "value" => $user_welcomededcription
,"name" => 'welcomelink'
, "value" => $user_welcomelink
,"name" => 'welcomelinktitle'
, "value" => $user_welcomelinktitle
,"name" => 'servicetitle'
, "value" => $user_servicetitle
,"name" => 'totalservicedisplay'
, "value" => $user_totalservicedisplay
,"name" => 'ourservice'
, "value" => $user_ourservice
,"name" => 'blogtitle'
, "value" => $user_blogtitle
,"name" => 'totalblogdisplay'
, "value" => $user_totalblogdisplay
,"name" => 'ourblog'
, "value" => $user_ourblog
,"name" => 'newstitle'
, "value" => $user_newstitle
,"name" => 'totalnewsdisplay'
, "value" => $user_totalnewsdisplay
,"name" => 'ournews'
, "value" => $user_ournews
,"name" => 'totaltestimonialdisplay'
, "value" => $user_totaltestimonialdisplay
,"name" => 'ourtestimonial'
, "value" => $user_ourtestimonial
, "entrydate" => $currentdatetime

);
if ($result != 0) {
$result = mysql_update($db, "user_options", $columns, "");
if ($result == true) {
$result = 'SUCCESS';
}
} else {
$result = mysql_insert($db, "user_options", $columns, "");
if ($result == true) {
$result = 'SUCCESS';
}
}
connectionclose($db);
return $result;
}

此代码仅插入最后一个值,如下所示

id          name             value
1 testimonials 5

我想插入这样的数据

id      name               value
1 slider 0
2 welcome box 1
3 welcome message hi

更新函数

     if (!function_exists('mysql_update')) {

function mysql_update($db, $table, $columns, $where = "") {
$sql = "UPDATE `" . $table . "` SET";
$arry = array();
foreach ($columns as $field => $value) {
array_push($arry, " `" . $field . "`='" . $value . "' ");
}
// implode keys of $array...
$sql .= implode(",", $arry);
if (isset($where) && $where != "") {
$sql .= " " . $where;
}
$result = mysql_query($sql, $db) or die(mysql_error());
return $result;
}

}

插入函数

       if (!function_exists('mysql_insert_multiple')) {

function mysql_insert_multiple($db, $table, $columns) {
$sql = "INSERT INTO `" . $table . "` ";
// implode keys of $array...
$sql .= " (`" . implode("`, `", array_keys($columns[0])) . "`)";
// implode values of $array...
$sql .= " VALUES ";
$tempstr = array();
foreach ($columns as $row) {
$tempstr[] = " ('" . implode("', '", $row) . "') ";
}
$sql.=implode(',', $tempstr);
$sql.=";";
$result = mysql_query($sql, $db) or die(mysql_error());
return $result;
}

}

最佳答案

您可以在循环中使用查询,一次将多个重新编码的内容插入到一个字段中。

关于php - 如何在一个具有不同ID的字段中插入多个文本框值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35078332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com