我需要帮助显示php select count语句

时间:2014-01-09 21:11:31

标签: php sql oracle select

我正在尝试在php中编写一个页面,目的是从数据库中计算指定的数据并显示该数据。这似乎是一个足够简单的任务,但我不能让它正常工作,我正处于我非常有限的PHP / SQL知识的极限。这是我整个页面的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Counter Test</title>
</head>

<body>

<div id="counter">

<?php
$advance = "(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xx.xx.xxx)(PORT = 1521)))
    (CONNECT_DATA =
      (SERVICE_NAME = domain.domain)))";

$conn = oci_connect('xxx', 'xxx', xxx);
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
    }

$stid = oci_parse($conn, 'SELECT count(distinct(b.id_number)) as total FROM bio b WHERE (b.alum_memb_type) is not null AND b.record_status_code NOT IN ('D', 'X', 'R')' );
oci_execute($stid);

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

</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

你可以期待一个结果,所以不必在循环中获取。

oci_execute($stid);

$row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);

$count = $row['total'];