没有显示从数据库返回的值

时间:2012-02-05 19:22:50

标签: php mysql html

我从表中得到某个列的总和,查询是正确的但是当我试图在表中显示它打印为零时。以下是我的DAO

public function getTotal_paid($id)
{
    $dbHandler = new dbConfig();
    $query="select SUM(payed) from itemsale where custId = $id";
    $results = $dbHandler->Query($query);
    return $results;
} // End-Function

以下是我的逻辑

public function getTotal_paid($id)
{
    $objDAO = new itemsaleDAO();
    $results = $objDAO->getTotal_paid($id);
    return $results;
} // End-Function

这是我的前端页面

<table cellpadding="0" cellspacing="0" border="1" align="right">
<tr><th style="height:10px" class="heading_text">Total Paid</th><th style="height:10px    width:10px" class="heading_text">Total Remaining</th></tr>
<?
include_once($commonLocation.'Logic/itemSaleLogic.php'); 
$var= new itemSale();
$object= new itemSaleLogic();
$object1= array();
$object1[0]= new stdClass;
$object1[0]->custId = $_GET['id'];
$var->payed=$object->getTotal_paid($object1[0]);
//$var->remaining=$object->getTotal_rem(6);
echo $var->payed;

echo "<tr><td class=\"inner_text\">".$var->payed."</td>";
//echo "<td class=\"inner_text\">".$var->remaining."</td></tr>";
?>
</table>

对象$ var-&gt; payed显示为零(忽略付费拼写)

1 个答案:

答案 0 :(得分:0)

这不会简化它吗?好像你是以奇怪的方式在课堂上跳来跳去。未经检查或测试,但作为如何改进的示例:

class itemsale:

public function getTotal_paid($id)
{
    global $dbHandler;    // important! this pulls your DB object in..

    $query="select SUM(payed) as itemSum from itemsale where custId = $id";   // note query change here!

    $results = $dbHandler->Query($query);

    return $results;
}

前端页面

include_once($commonLocation.'Logic/itemSaleLogic.php'); 

$dbHandler = new dbConfig();  // make sure you have your DB object...

$var= new itemSale();

$var->getTotal_paid(intval($_GET['id']));

var_dump($var);    // for debug

echo $var->itemSum;  // to output your sum.. do with what you want!


?>