model文件:
public function get_avgprice_item($category_id){
$sql = "SELECT AVG(yj) FROM " . $this->get_table('item') . ' where category_id = ' . intval($category_id);
return $this->query_all($sql);
}
main文件:
TPL::assign('avgprice', $this->model('item')->get_avgprice_item($category_info['id']));
htm文件:
<?php echo $avgprice; ?>
Please tell me why Array is returned in HTML. You can get the result when executing in SQL. The SQL statement is correct.
Under each specific page, the corresponding SQL statement can be printed and the assignment variable is correct. I don’t know why it just returns Array
Maybe it’s because you didn’t return
Try this
I think you can try to solve it like this
step 1.
step 2.
Regarding the query result being Array, it may be query_all(). There is a problem with this method. Please check if there is a function similar to query_one()
Change echo to var_dump or print_r. Echo cannot print array structures.
The get_avgprice_item() function has no return. When the function method does not return any variables or methods, the system defaults to the function and method returning null
And if you look at $this->query_all($sql); there is no assignment after query Give any variables and no return parameters, the correct way