根据值从OCI拆分表
问题描述:
我正在通过OCI连接器查询带有SQL查询的oracle数据库。我期待根据一列中的值拆分我返回的数组。根据值从OCI拆分表
因此,在这个例子中,基于“位置”列中的值,我想分开的表。我已经能够通过使用if((floorid == $ row ['LOCATION'])并且将floor ID设置为其中一个值来分隔其中一个位置,但是我无法复制这些以用于所有可能性。复制标题任何帮助,将不胜感激
$stid = oci_parse($conn, $query);
oci_bind_by_name($stid, ":getparam", $safeparam1);
$r = oci_execute($stid);
print '<hr>';
print '<table class="style1">';
Print '<tr><th>Name</th><th>Location</th><th>Colour</th></tr>';
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS + OCI_ASSOC)) {
print '<tr>';
foreach($row as $item) {
print '<td>' . ($item !== null ? htmlentities($item, ENT_QUOTES) :
'') . '</td>';
}
print '</tr>';
}
print '</div>';
oci_free_statement($stid);
oci_close($conn);
答
修改SQL命令由LOCATION
场结果:
order by location
然后,在你while
循环,检测时LOCATION
变化值和开始新表:
$stid = oci_parse($conn, $query);
oci_bind_by_name($stid, ":getparam", $safeparam1);
$r = oci_execute($stid);
print '<hr>';
print '<table class="style1">';
print '<tr><th>Name</th><th>Location</th><th>Colour</th></tr>';
$location = -1; // keeps track of the location change.
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS + OCI_ASSOC)) {
if ($location == -1) {
// seems to be the first row; set $location so we don't end up with an empty first table.
$location = $row['LOCATION'];
}
if ($row['LOCATION'] != $location) {
$location = $row['LOCATION'];
// close previous table; start new table.
print '</table><table class="style1">';
print '<tr><th>Name</th><th>Location</th><th>Colour</th></tr>';
}
print '<tr>';
foreach ($row as $item) {
print '<td>' . ($item !== null ? htmlentities($item, ENT_QUOTES) : '') . '</td>';
}
print '</tr>';
}
print '</table>';
oci_free_statement($stid);
oci_close($conn);
@JamesPavett对此有何反馈? – timclutton