简体   繁体   中英

Fetching data using where clause

This is my categories. If i click on a category then it goes to its view page, and show all products related with this selected category. 在此处输入图片说明

I am trying like this.But it is not working.Can you please anyone help me to solve this problem?I am using 3 tables for this situation. 1.categories 在此处输入图像描述类别表

2.products 在此处输入图片说明 3.product_cat

在此处输入图片说明

Controller:

<?php 
class Clothing extends Controller{

    function product_details(){
        $id=$this->uri->segment(3);

        $this->load->model('Products_model');
        $data['products']=$this->Products_model->product_details($id);

        //$this->load->view('clothe',$data);
    }
}

?>

Model:

<?php
class Products_model extends Model {
    function product_details($id){
                    $query=$this->db->select("*")
                    ->from("product_cat")
                    ->where("categories_id",$id);
                    return $query;
        }
    }

View:

<html>
    <head></head>
    <body>

        <?php  foreach ($products as $v_menu) { ?>
                    <?php echo $v_menu; ?>
        <?php } ?>
    </body>
</html>

You can join the two tables products and product_cat as below so that you can get the product details too-

return $query=$this->db->select('*')
        ->from('product a')
        ->from('product_cat p')
        ->where("p.product_id = a.id")
        ->where('p.categories_id =', $id)
        ->get()->result();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM