Php codeigniter在另一个查询中使用部分查询结果
很难想出一个头衔。我将CodeIgniter与模型/视图/控制器一起使用。我的MySQL数据库中有以下相关表格: 在我的模型中,我具有以下功能:Php codeigniter在另一个查询中使用部分查询结果,php,mysql,codeigniter,Php,Mysql,Codeigniter,很难想出一个头衔。我将CodeIgniter与模型/视图/控制器一起使用。我的MySQL数据库中有以下相关表格: 在我的模型中,我具有以下功能: function get_shoptable() { $this->db->from('productshop')->where('productId', $this->productId); $query = $this->db->get(); return $query->resu
function get_shoptable() {
$this->db->from('productshop')->where('productId', $this->productId);
$query = $this->db->get();
return $query->result();
}
在我的控制器中,我使用上面的函数
$data['bookshop'] = $this->Product_model->get_shoptable();
在我看来,我是在找一家书店。我的问题是,显示shopName而不是显示shopId的最佳方式是什么。考虑到$bookshop应该保持原样(shopid除外),因为我正在创建一个包含产品数据的HTML表。尝试以下方法:
function get_shoptable() {
$this->db->from('productshop')
->join('shop', 'productshop.shopId = shop.shopId')
->where('productshop.productId', $this->productId);
$query = $this->db->get();
return $query->result();
}
试试这样的方法:
function get_shoptable() {
$this->db->from('productshop')
->join('shop', 'productshop.shopId = shop.shopId')
->where('productshop.productId', $this->productId);
$query = $this->db->get();
return $query->result();
}
了解codeigniter的详细功能
function get_shoptable()
{
$this->db->from('productshop')
$this->db->join('shop', 'productshop.shopId = shop.shopId')
$this->db->where('productshop.productId', $this->productId);
$query = $this->db->get();
return $query->result();
}
了解codeigniter的详细功能
function get_shoptable()
{
$this->db->from('productshop')
$this->db->join('shop', 'productshop.shopId = shop.shopId')
$this->db->where('productshop.productId', $this->productId);
$query = $this->db->get();
return $query->result();
}
型号:
控制器:
function products() {
$data['products'] = $this->model_name->get_product();
$this->load->view('products', $data);
}
视图:
型号:
function get_products() {
$this->db->select('productshop.productUrl, productshop.price, productshop.deliveryTime, productshop.shippingCast, productshop.inventory, productshop.productId, productshop.shopId, shop.shopName');
$this->db->from('productshop');
$this->db->join('shop', 'productshop.shopId = shop.shopId');
$this->db->where('productshop.productId', $this->productId);
return $this->db->get()->result_array();
}
控制器:
function products() {
$data['products'] = $this->model_name->get_product();
$this->load->view('products', $data);
}
视图:
不要使用结果集中的shopId。或者使用select语句为您的评论选择特定的列标记。你的回答对我没什么帮助,也许我应该具体回答我的问题。我可以做一个查询,从productshop获取所有数据(受productId的限制)并从shop获取所需的shopName吗?@Orhan,检查我的答案,如果你想,我可以在所有示例中进行扩展。只是不要使用结果集中的shopId。或者使用select语句选择特定的列感谢你的评论。你的回答对我没什么帮助,也许我应该具体回答我的问题。我可以做一个查询,从productshop获取所有数据(受productId限制)并从shop获取所需的店名吗?@Orhan,检查我的答案,如果你想,我可以在所有示例中进行更多扩展。非常酷,谢谢,成功了!但是,如果您不选择shopName,该如何工作呢?在探查器中,我看到这样的查询构建:SELECT*FROM(productshop
)JOINshop
ONproductshop
shopId
shopId
WHEREproductshop
productId
=116774非常酷,谢谢,效果不错!但是,如果您不选择shopName,该如何工作呢?在探查器中,我看到这样的查询构建:SELECT*FROM(productshop
)JOINproductshop
上的shopId
=shopId
其中productshop
productId
=116774