在3列错误中分裂mysql数据 [英] Spliting mysql data in 3 columns error

查看:85
本文介绍了在3列错误中分裂mysql数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上午,

我们有一个脚本用于分割我们从mysql数据库获得的数据(基于这个答案: https://stackoverflow.com/a/8660624/1067100 )在一个有三列的表中,在当前的例子中,我们有一个数据库返回8值,但出现9(后者完全为空)。



当前图像可以澄清问题,如果它已经变得非常清楚,并且还链接到我们认为的代码是错的。我们已经审查过,但我们无法找出问题所在。:/ b / b
$ b

代码: https://gist.github.com/99df1288cd1d998c8172




在此先感谢。

解决方案

最快的解决方法是你需要一个)计算($ j ++){
) count($ data)){
break;

$ / code>

请注意,您应该通过存储计数来节省计算能力的一小部分($数据)在一个变量 - 除非你期望计数改变。

  $ countOfData = count($ data); ($ j = 0; $ j <3; $ j ++){
if($ i = 0; $ i <$ countOfData / 3; $ i ++){

($ i * 3)+ $ j> = $ countOfData){
break;
}


Morning,

We have a script for spliting the data we get from a mysql database (based on this answer: https://stackoverflow.com/a/8660624/1067100) in a table with three columns, in the case of the current example, we have a database that returns 8 values ​​but appear 9 (latter completely empty).

The current image can clarify the problem if it has become abundantly clear, and also a link to the code we think is wrong. We have reviewed but we are not able to find out what the problem.. :/

the code: https://gist.github.com/99df1288cd1d998c8172

Thanks in advance.

解决方案

The queickest fix is that you need a "break" in the inner loop.

for ($i=0; $i < count($data)/3; $i++){
    for ($j=0; $j<3; $j++){
         if (($i * 3) + $j >= count($data)) {
             break;
         }

Note that you should save a fractional bit of computing power by storing count($data) in a variable - unless you expect the count to change.

$countOfData = count($data);
for ($i=0; $i < $countOfData/3; $i++){
    for ($j=0; $j<3; $j++){
         if (($i * 3) + $j >= $countOfData) {
             break;
         }

这篇关于在3列错误中分裂mysql数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆