拆分oracle将数据分成4列

问题描述 投票:0回答:1

我从oracle中选择了视图,它返回了11行。我想获取数据并将它们打印成4列。应该是这样的:

Item 1     Item 2     Item 3      Item 4 
Item 5     Item 6     Item 7      Item 8
Item 9     Item 10    Item 11     Item 12
Item 13.......

这是我的2列代码。但如何为4列做到这一点?

另外我不明白为什么oci_num_rows只在while(oci_fecth_data)之后显示行数

<?php
$stmt1 = oci_parse($conn, $query1);
oci_execute($stmt1);
$mssqlaray = array();
$index = 0;
while (($row1 = oci_fetch_array($stmt1, OCI_BOTH))) 
{
  $mssqlaray[$index] = $row1;
    $index++;
}

for($j = 0; $j < oci_num_rows($stmt1); $j+=2)
{
  echo '
  <div class="col-sm-6">
        <div class="checkbox checkbox-primary">
            <input id="checkbox1'.$mssqlaray[$j][0].'" type="checkbox">
            <label for="checkbox1'.$mssqlaray[$j][0].'">'.$mssqlaray[$j][1].'   </label>
        </div>
    </div>';
}
for($j = 1; $j < oci_num_rows($stmt1); $j+=2)
{
    echo '
  <div class="col-sm-6">
        <div class="checkbox checkbox-primary">
            <input id="checkbox1'.$mssqlaray[$j][0].'"type="checkbox">
            <label for="checkbox1'.$mssqlaray[$j][0].'">'.$mssqlaray[$j][1].'</label>
        </div>
    </div>';
}
php oracle
1个回答
1
投票

如果我理解正确,这应该是你想要的。当然你仍然可以添加div或类等内容。我想,我只是给你我的方法的骨架。

<?php
$stmt1 = oci_parse($conn, $query1);
oci_execute($stmt1);
$mssqlaray = array();
$index = 0;
while (($row1 = oci_fetch_array($stmt1, OCI_BOTH))) 
{
    $mssqlaray[$index] = $row1;
    $index++;
}

echo '<table>'."\n";
echo '<tr>'."\n";

for($i = 0; $i < count($mssqlaray); $i++)
{
    echo '<td>'.$mssqlaray[$i].'</td>';
    if(i == 3 || i == 7 || i == 11){
        echo '</tr>'."\n";
        echo '<tr>'."\n";
    }
}
echo '</tr>'."\n";
echo '</table>."\n";
?>
© www.soinside.com 2019 - 2024. All rights reserved.