首页 \ 问答 \ 使用PHP implode函数使用一个INSERT语句将多行插入MySql(Inserting multiple rows into MySql with one INSERT statement using PHP implode function)

使用PHP implode函数使用一个INSERT语句将多行插入MySql(Inserting multiple rows into MySql with one INSERT statement using PHP implode function)

我正在尝试使用implode函数将多行插入到MySql中,只有一个INSERT INTO语句。 它是从这里发现的。

我的示例代码如下。

$sql[]=array();
$len=count($colour_id);
for($i=0;$i<$len;$i++)
{
     $sql[]='('.$colour_id[$i].', '.$_POST['prod_id'].')';
}

$l=count($sql);
foreach($sql as $temp)
{
     echo $temp;
}

echo 'insert into product_colour (colour_id, prod_id)values '.implode(',', $sql);

上面的代码只是初始化$sql数组, foreach循环遍历数组并显示数组的内容,如下所示。

Array(1, 1)(2, 1)(3, 1)

但是在回显最后一个语句(insert语句)时,它显示以下错误。

Notice: Array to string conversion in C:\wamp\www\wagafashion\ProductColour.php on line 70
insert into product_colour (colour_id, prod_id)values Array,(1, 1),(2, 1),(3, 1) 

(第70行代表上面代码片段中的最后一行)。 应该进行哪些更改,以便可以将存储在数组中的值插入到MySql数据库中?


I'm trying to insert multiple rows into MySql with only one INSERT INTO statement using the implode function. It was found from here.

My sample code goes below.

$sql[]=array();
$len=count($colour_id);
for($i=0;$i<$len;$i++)
{
     $sql[]='('.$colour_id[$i].', '.$_POST['prod_id'].')';
}

$l=count($sql);
foreach($sql as $temp)
{
     echo $temp;
}

echo 'insert into product_colour (colour_id, prod_id)values '.implode(',', $sql);

The above code simply initializes the $sql array and the foreach loop iterates over the array and displays the content of the array as follows.

Array(1, 1)(2, 1)(3, 1)

but while echoing the last statement (insert statement), it shows the following error.

Notice: Array to string conversion in C:\wamp\www\wagafashion\ProductColour.php on line 70
insert into product_colour (colour_id, prod_id)values Array,(1, 1),(2, 1),(3, 1) 

(line no 70 means the last line in the above code snippet). What changes should be made so that I can insert the values stored in the array into MySql database?


原文:https://stackoverflow.com/questions/9796084
更新时间:2022-03-16 06:03

最满意答案

以下是解决方案,以您未放入font-family的样式为例:{{font.family}}; http://pastebin.com/WmBv5XDB


Here is the Solution, in the style you are not putting font-family:{{font.family}}; http://pastebin.com/WmBv5XDB

相关问答

更多
  • 我使用这个功能 - 在Safari,Chrome,Firefox,Opera,IE7,IE8,IE9中测试: function waitForWebfonts(fonts, callback) { var loadedFonts = 0; for(var i = 0, l = fonts.length; i < l; ++i) { (function(font) { var node = document.createElement('span'); ...
  • 尝试添加条件链接到您的页面,链接到Font Awesome提供的单独的font-awesome-ie7.css 。 有关详细信息,请参阅问题#38 。 Try adding a conditional link to your page, linking to the separate font-awesome-ie7.css that ...
  • 以下是解决方案,以您未放入font-family的样式为例:{{font.family}}; http://pastebin.com/WmBv5XDB Here is the Solution, in the style you are not putting font-family:{{font.family}}; http://pastebin.com/WmBv5XDB
  • 你可以在样式表中使用这样的东西 @import url('https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i'); h2{ font-family:Roboto; } you can use like this in your stylesheet @import url('https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i'); h2{ font-f ...
  • “Razor检查任何@字符右侧的内容,并尝试确定它是否是C#代码(如果它是CSHTML文件)。 如果内容作为代码有效(并且您希望将其视为内容),则可以通过键入@@显式地转义@字符。“ http://weblogs.asp.net/scottgu/introducing-razor 在font-face的.cshtml文件中添加@@而不是@。 "Razor examines the content on the right-hand side of any @ character and attempts t ...
  • 我不知道浏览器是如何实现它的,但CSS字体模块3级在其“ 字体加载指南 ”部分中说,浏览器必须只下载当前页面中使用的字体 : @ font-face规则旨在允许延迟加载字体,仅在需要在文档中使用时下载字体。 样式表可以包括@ font-face规则,用于仅使用选择集的字体库; 用户代理只能下载适用于给定页面的样式规则中引用的那些字体。 下载@ font-face规则中定义的所有字体而不考虑这些字体是否实际在页面中使用的用户代理被认为是不符合要求的。 因此,无论如何,在您的代码中,您无法指定任何特定行为,如果 ...
  • 我已经在本地测试了这一点,从我的结果我可以说,这绝对是因为你赋予了每个“字体重量”属性的价值。 这些不存在: 中 瘦 extrathin 将它们更改为适当的重量,并且它将正常工作。 http://www.w3schools.com/cssref/pr_font_weight.asp 唯一一个看起来正确的是设置为'正常',所以有趣的是浏览器(我测试它在铬)总是加载在最后一个声明... I've tested this locally and from my results i can say that it ...
  • 这是Chrome的一个已知的错误 。 它已被修复,请等待更新? 或者,您可以强制通过CSS(从错误报告中获取)重新绘画,该CSS应显示字体: body { -webkit-animation-duration: 0.1s; -webkit-animation-name: fontfix; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: linear; -webkit-an ...
  • 事实证明这不是一个问题。 似乎AJAX内容的post-load事件就像window.load一样,而不是document.ready。 This actually turns out to be a non-issue. It seems that the post-load event for AJAX content behaves like a window.load would, as opposed to a document.ready.
  • jQuery有一个函数fontAvailable,你可以检查是否加载了fontface字体: $(document).ready(function() { if(!$.fontAvailable('FontFaceFontName')) { // Your Cufon Replace Code } }); jQuery has a function fontAvailable where you can check if the fontface font is loade ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)