我正在尝试组合两个表并得到如下所示的结果,但目前我没有得到我想要的输出
期望的输出
weight_pounds height_cm
121.25 130
132.28 160
154.32 221
176.37 434
我有两张桌子,每张桌子上都有一个 foreign_key 列creater_id
user_weight 表
user_height 表
我试过这个功能,但它显示错误的输出:
function get_all_user_bmi($uid)
{
$this->load->database();
$this->db->select('w.weight_pounds, h.height_cm');
$this->db->from('user_weight w');
$this->db->join('user_height h' ,'w.creater_id = h.creater_id');
$this->db->where('w.creater_id',$uid);
$this->db->where('h.creater_id',$uid);
$this->db->group_by(array('h.height_id'));
$this->db->order_by('w.uweight_id', 'ASC')->order_by('h.height_id', 'ASC');
//$this->db->group_by('h.height_id','w.uweight_id');
$this->db->distinct();
$res = $this->db->get();
$ret = array();
foreach ($res->result_array() as $row) {
$weight=$row['weight_pounds']* 4.88;
$height=($row['height_cm']*0.032808)*($row['height_cm']*0.032808);
$bmi=$weight/$height;
$ret[] = $bmi; //final bmi formuala calculated
}
print($this->db->last_query());
return $ret;
}
通过执行上面的 php 代码获得不同的输出(不正确)