简体   繁体   中英

How to apply filter on JSON format database in CodeIgniter

I have a database of a table named ' literature ' in this table there is only one column " item_details " having data in JSON format as given below:-

{
    "book":[
            {
                "language":"English",
                "author":["Y.Nikhilendra","Paresh Khairnar","Madhabendra Rout"]
            },
            {
                "language":"English",
                "author":["Sai Seetharam Nomula"]
            }
        ],
    "diary":[
            {
                "language":"Hindi",
                "author":["Partha Banerjee"]
            },
            {
                "laguage":"English",
                "author":["Gaurav Pandey"]
            }
        ]
}

I want to apply filter option according to languages in CodeIgniter . in the controller

public function view()
{
    $response = $this->view_model->viewModel( $language);       
}

Model:-

public function viewModel($language)
{
    $this->db->select(*);
    $this->db->from('literature');
    $this->db->where
    //What would be structure of where clause?
}

Use json_extract

WHERE(json_extract(json_each.value, '$.email') LIKE '%criteria%');

Reference Link

Edit:

if you see function does not exist then may this answer will help you. answer link

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