【问题标题】:Getting Column Name from SQL for PHP webpage从 SQL for PHP 网页获取列名
【发布时间】:2018-12-19 04:55:15
【问题描述】:

我正在尝试构建一个 PHP 页面。我有这个部分,它从 Oracle 数据库中获取结果而没有标题。谁能指出我,我如何显示结果以及列标题。 / 获取查询结果

print "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
            print "<tr>\n";
    foreach ($row as $item) {
        print "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
    }
    print "</tr>\n";
}
print "</table>\n";

提前谢谢你

【问题讨论】:

标签: php oracle11g


【解决方案1】:
print "<table border='1'>\n";
$header = false;
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {

if($header == false) {
print '<thread><tr>';
foreach (array_keys($row) as $key) {
print '<th>'.($key !== null ? htmlentities($key, ENT_QUOTES) : '').'</th>'; }
print '</tr></thread>';
$header = true;
}

            print "<tr>\n";
    foreach ($row as $item) {
        print "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
    }
    print "</tr>\n";
}
print "</table>\n";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-22
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多