简体   繁体   English

将列结果显示为行结果php

[英]Display column result as row result php

I am sure the title is not even right on this one. 我相信这个标题甚至不正确。 Here is the issue , I have 3 columns and 6 results that are displayed like this 这是问题,我有3列和6个结果像这样显示

Column1           Column2             Column3
result1           result3             result5
result2           result4             result6

but need them like this 但需要他们这样

Column1           Column2             Column3
result1           result2             result3
result4           result5             result6

my array holds all 6 results and so far I see I need to pick every 0 and 2nd to be displayed in column1 and continue( array starts at 0). 我的数组包含所有6个结果,到目前为止,我看到我需要选择每个0和2nd才能在column1中显示并继续(数组从0开始)。

the code is pretty large but the main part for switching results is here 代码很大,但是切换结果的主要部分在这里

$count = count($result);
for ($result = 0; $result < $count; $result++) {
                    $getorder= "";
                    if ($count != 1) {
                        if ($result == 0) $getorder= "first";
                        if ($result == $count - 1) $getorder= "last";
                    }


    echo '<div class="'.$getorder.'width'.intval(100 / $count).'">'.$mycolumn[$result].'</div>';
}

so this here should have some kind of division. 所以这里应该有某种划分。 Here is just dumb example 这是一个愚蠢的例子

$mycolumn[$result % X == X]

i hope I did not confuse you and you get the idea. 希望我不要让您感到困惑,您会明白的。 If you ask yourself why i don't just do rows instead columns , answer is complete css reconstructions. 如果您问自己为什么我不只是做行而不是做列,答案就是完整的CSS重构。 whit this here figured out I can target the results and keep columns and css as they are 在这里,我想出了我可以定位结果并保持列和css不变

Don't use ($result / 3) since you can have seriuous rounding problem . 不要使用($result / 3)因为你可能有严重的舍入问题 Since to me it's not very clear the name of your vars I post you a php generic code and it is: 既然对我而言,你的vars名称不是很清楚,我发布了一个php通用代码,它是:

echo '<div class="result">';
for($i = 0; $i < $columnNum; $i++)
{
   echo '<div class="column">';
   for($j = $i; $j < $resultNum; $j += $columnNum)
      echo '<label class="value">' . array[j] . "</label>";
   echo '</div>';
}
echo '</div>';

Just change the vars name with your needs and this is the solution to your problem. 只需根据您的需要更改vars名称,这就是您的问题的解决方案。

$mycolumn[intval($result / 3) + intval(($result % 3) * $count / 3)]

Demo http://codepad.viper-7.com/hdSi6b 演示http://codepad.viper-7.com/hdSi6b

Working flawlessly. 工作完美无瑕。

You can change whole code as AurelioDeRosa said. 你可以改变整个代码,如AurelioDeRosa所说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM