这是我的代码。它只插入最后一个元素值。我想在一个具有不同id的字段中插入所有值,并将所有数据插入到不同的不同行中。
var ndx = crossfilter(final_data);
var dim_pie = ndx.dimension(function(d) {return d.status;});
var fact_pie = dim_pie.group().reduceSum(function(d) {return +d.nos;});
这段代码只插入像这样的最后一个值
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;
}
}
答案 0 :(得分:0)
将您的sql更改为:
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("', '", array_values($row)) . "') ";
$sql.=implode(',', $tempstr);
$sql.=";";
$result = mysql_query($sql, $db) or die(mysql_error());
}
return $result;
}
如果你的$ column数组格式为:
,这将有效$columns = array(
0 => array("name" => 'slider'
"value" => $user_slider.
1 =>
.
.
.
所以我认为您还需要更改$ column数组。
答案 1 :(得分:0)
您可以在循环中使用您的查询,以便一次在字段中插入多次重新编码。