简体   繁体   English

不显示数据库返回的值

[英]not showing value returned from database

i am getting sum of of a certain column from a table, query is right but when i am trying to show that in a table it prints zero. 我正在从表中获取某列的总和,查询是正确的,但是当我尝试显示在表中时它显示为零。 following is my DAO 以下是我的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

Following is my logic 以下是我的逻辑

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

Here is my front end page 这是我的前端页面

<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>

the object $var->payed is showing zero(ignore spellings of paid) $ var-> payed对象显示为零(忽略payed的拼写)

Would this not streamline it? 这不会精简吗? seems like you are hopping around classes in an odd way. 好像您是在以奇怪的方式来上课。 Not checked or tested, but as an example of how it might be improved: 未经检查或测试,但作为改进示例:

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;
}

front end page 前端页面

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!


?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM