使用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 theimplode
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 theforeach
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
最满意答案
以下是解决方案,以您未放入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 ...
-
@ font-face无法加载一些请求,由于JavaScript?(@font-face fails to load on some requests, due to javascript?)[2023-08-05]
这是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 ...