admin管理员组文章数量:1330660
I have a problem I cannot separate the array by commas if I put the implode it only shows the first number and not the second in database i need insert in database 500,756
global $wpdb; $arg=array(500,756); $var = implode(",", $arg); --> return in db 500 ->I can not separate by commas, num 500 is only show in db $var = implode($arg); --> if i put this instead of the other return in db shows 500756 $wpdb->insert('number',array( 'num' => $var, ));
CREATE TABLE `number` ( `id` int(255) NOT NULL, `num` varchar(255) NOT NULL, ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ALTER TABLE `number` ADD PRIMARY KEY (`id`); ALTER TABLE `number` MODIFY `id` int(255) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=39;
I have a problem I cannot separate the array by commas if I put the implode it only shows the first number and not the second in database i need insert in database 500,756
global $wpdb; $arg=array(500,756); $var = implode(",", $arg); --> return in db 500 ->I can not separate by commas, num 500 is only show in db $var = implode($arg); --> if i put this instead of the other return in db shows 500756 $wpdb->insert('number',array( 'num' => $var, ));
CREATE TABLE `number` ( `id` int(255) NOT NULL, `num` varchar(255) NOT NULL, ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ALTER TABLE `number` ADD PRIMARY KEY (`id`); ALTER TABLE `number` MODIFY `id` int(255) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=39;Share Improve this question edited Jul 14, 2020 at 19:12 Howdy_McGee♦ 20.9k24 gold badges91 silver badges177 bronze badges asked Jul 14, 2020 at 5:07 StymarkStymark 372 bronze badges 3 |
1 Answer
Reset to default 0implode(",", [500,756])
will definitely return "500,756"
, therefore you have some other problem.
If the field type of the 'num' field is a numeric type such as MySQL's INT, then MySQL or PHP might try and convert this string to a number and so "500,756"
could become 500
.
Check the data type of the 'num' field in the 'number' table. To store the string you want to store it needs to be a string type such as VARCHAR. Or if you're trying to store a number with stuff after the decimal point make sure it's e.g. a FLOAT / DECIMAL, etc. and add the value using a decimal point, e.g. 500.756
.
If you need further help, show the CREATE TABLE output for your table
本文标签: phpI can39t separate the array by commas
版权声明:本文标题:php - I can't separate the array by commas 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742262460a2442769.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
num
column? If it's an integer column of any kind then you can't insert comma separated values. – Jacob Peattie Commented Jul 14, 2020 at 5:21