【问题标题】:How to fetch data in specific rows and columns in php using oracle database如何使用oracle数据库在php中获取特定行和列中的数据
【发布时间】:2021-09-23 20:57:27
【问题描述】:

这是表格,但你能帮我把这样的数据放上去吗

这里 s.no 计数增加,单元格名称 1 的值来自不同的表。

我想要的是在类别 1 行中显示类别 1(汽车部门)的数据 html 表中的类别 2 行中的类别 2(汽车部门),依此类推

【问题讨论】:

  • 这是查询数据库的问题,还是仅仅显示在网页上?
  • 在 html 表上,(网页)我有查询,但我不知道如何获取相应行中的数据
  • 我没有,也不认识任何拥有 Oracle 数据库的人,所以除了向您指出 PHP documentation for querying it 之外,我无法真正帮助您。
  • 请提供文本格式的示例数据和文本格式的所需输出。现在完全不清楚,你有什么列以及你想在每列中放什么(因为我不明白,列名在哪里,列值在哪里)。这种类型的信息也可以复制粘贴为文本,更具可读性,至少可以轻松编辑以使其可读
  • 您对此有何疑问?你试图解决这个问题是什么?你被困在哪里了?

标签: php oracle loops html-table


【解决方案1】:

这是一个可以使用的示例 sn-p。 OCI8 manual The Underground PHP and Oracle Manual 也会有所帮助。

<?php

error_reporting(E_ALL);  // In PHP 5.3 use E_ALL|E_STRICT
ini_set('display_errors', 'On');

$c = oci_connect('cj', 'cj', 'localhost/orclpdb1');
if (!$c) {
    $m = oci_error();
    trigger_error('Could not connect to database: '. $m['message'], E_USER_ERROR);
}

$s = oci_parse($c, "select * from employees where salary > :sbv");
if (!$s) {
    $m = oci_error($c);
    trigger_error('Could not parse statement: '. $m['message'], E_USER_ERROR);
}
$salary = 15000;
$r = oci_bind_by_name($s, ':sbv', $salary);
if (!$r) {
    $m = oci_error($s);
    trigger_error('Could not bind a parameter: '. $m['message'], E_USER_ERROR);
}
$r = oci_execute($s);
if (!$r) {
    $m = oci_error($s);
    trigger_error('Could not execute statement: '. $m['message'], E_USER_ERROR);
}

echo "<table border='1'>\n";
$ncols = oci_num_fields($s);
echo "<tr>\n";
for ($i = 1; $i <= $ncols; ++$i) {
    $colname = oci_field_name($s, $i);
    echo "  <th><b>".htmlspecialchars($colname,ENT_QUOTES|ENT_SUBSTITUTE)."</b></th>\n";
}
echo "</tr>\n";

while (($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
    echo "<tr>\n";
    foreach ($row as $item) {
        echo "<td>";
        echo $item!==null?htmlspecialchars($item, ENT_QUOTES|ENT_SUBSTITUTE):"&nbsp;";
        echo "</td>\n";
    }
    echo "</tr>\n";
}
echo "</table>\n";

?>

【讨论】:

    猜你喜欢
    • 2013-07-20
    • 2016-02-11
    • 2016-12-31
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-05
    • 1970-01-01
    相关资源
    最近更新 更多