gpt4 book ai didi

php - 从模型中的 Codeigniter View 中的两个相关选择查询中获取数据

转载 作者:行者123 更新时间:2023-11-29 23:05:11 24 4
gpt4 key购买 nike

class index_model extends CI_Model {

public function get_data()
{

$query = $this->db->query('SELECT * FROM sgrn_tblrecipe_addnew ORDER BY POPULARITY DESC LIMIT 4');
$result=$query->result();
foreach($result as $row)
{

$variable=$row->RECIPE_ID;
$this->myOtherFunction($variable);
}
return $result;
}
function myOtherFunction($variable)
{

$query = $this->db->query('SELECT * FROM sgrn_tblrcp_user_like WHERE RECIPE_ID="'.$variable.'"');
$result =$query->num_rows();
echo $result;
return $result;
}
}

您好,我尝试了我开发的这段代码,用于访问不同变量中的不同表数据,但我有一个问题,它没有给出第二个查询的结果。

实际上,我通过传递变量作为参数来使用函数调用技术...如果有任何其他方法可用,那么建议我...

我必须在MODEL中使用多个选择查询来通过不同的表从数据库中获取数据,但是在通过这些ID获取第一个查询结果后,我必须在第二个查询中使用WHERE 子句从不同的表中给出不同的结果....这两个结果在 VIEW 上作为不同的数据进行查看

最佳答案

您可以通过像下面的示例那样构建代码来实现相同的结果

$this->db->select('*');
$this->db->from('R_dropzones');
$query = $this->db->get();
$dropzone_list = $query->result();

if(!empty($dropzone_list))
{
$count=0;
$j=0;
foreach ($dropzone_list as $k=>$v)
{
/* Count Dropzone Qty */
$this->db->select('u_drop_zone');
$this->db->from('R_units');
$this->db->where(array('u_status'=>'DZ','u_drop_zone'=>$v->dz_id));
$unit_query = $this->db->get();
$unit_count = $unit_query->num_rows();

if( $unit_count > 0 )
{
$this->msg['Dropzone'][$j]['dz_qty']=$unit_count;
$this->msg['Dropzone'][$j]['dz_id']=$v->dz_id;
$this->msg['Dropzone'][$j]['dz_desc']=$v->dz_desc;
$this->msg['Dropzone'][$j]['dz_barcode']=$v->dz_barcode;
$j++;
$count++;
}
}

}

关于php - 从模型中的 Codeigniter View 中的两个相关选择查询中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28322081/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com