我正在尝试在codeigniter中运行查询。我在mysql中得到了正确的结果,但在codeigniter中它没有输出..这是我的查询:
$saleid = $data_row->saleid;
$billerid = $data_row->biller_id;
if ($billerid == 7) {
$discount = $data_row->total_discount;
$query = "select sum(net_unit_price*quantity) as scanning_charge from sma_sale_items where sale_id=" . $saleid;
$queryres = $this->db->query($query);
if ($queryres->num_rows > 0) {
foreach ($queryres->result() as $queryres1) {
echo print_r($queryres1);
$scanning_charge = $queryres1->scanning_charge;
}
} else {
die(mysql_error());
}
}
我不知道哪里出错了..用mysql可以。任何人都可以帮我找到我错的地方..提前致谢。
答案 0 :(得分:0)
使用此代码检查错误并打印上一个查询:
die($this->db->last_query());
将错误代码放在此处。
确保您的codeigniter环境是开发以显示错误代码。
答案 1 :(得分:0)
我发现了我的错误..
问题在于$ queryres-> num_rows()。我忘了放括号。
$saleid=$data_row->saleid;
$billerid=$data_row->biller_id;
if($billerid==7)
{
$discount = $data_row->total_discount;
$query = "select sum(net_unit_price*quantity) as scanning_charge from sma_sale_items where sale_id=".$saleid;
$queryres = $this->db->query($query);
if($queryres->num_rows() > 0)
{
foreach($queryres->result() as $queryres1)
{
echo print_r($queryres1);
$scanning_charge = $queryres1->scanning_charge;
}
}
答案 2 :(得分:0)
试试这个。可能这会对你有帮助。
$result = $this->db->select('SUM(net_unit_price*quantity) as scanning_charge')
->from('sma_sale_items')
->where('sale_id', $saleid)
->get()
->result();
if ($result) {
foreach ($result as $queryres) {
echo $scanning_charge = $queryres->scanning_charge;
}
} else {
echo "Record Not Exist";
}