From e86b0a2f8673f1ba8142e56f6b977a95523bbddd Mon Sep 17 00:00:00 2001 From: int2001 Date: Fri, 18 Aug 2023 14:42:04 +0000 Subject: [PATCH] get_fav implemented --- application/controllers/User_options.php | 11 ++++++++++- application/models/User_options_model.php | 14 ++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/application/controllers/User_options.php b/application/controllers/User_options.php index c5360590..1967349e 100755 --- a/application/controllers/User_options.php +++ b/application/controllers/User_options.php @@ -16,7 +16,16 @@ class User_Options extends CI_Controller { } else { $option_name=$obj['band'].'/'.$obj['mode']; } - $this->user_options_model->set_option('Favourite',$option_name, $obj); + return $this->user_options_model->set_option('Favourite',$option_name, $obj); + } + + public function get_favs() { + $result=$this->user_options_model->get_options('Favourite'); + foreach($result->result() as $options) { + $jsonout[$options->option_name][$options->option_key]=$options->option_value; + } + header('Content-Type: application/json'); + echo json_encode($jsonout); } } diff --git a/application/models/User_options_model.php b/application/models/User_options_model.php index 1304abd0..e37b8151 100644 --- a/application/models/User_options_model.php +++ b/application/models/User_options_model.php @@ -1,7 +1,7 @@ db->where('user_id', $this->session->userdata('user_id')); $this->db->where('option_type', $option_type); @@ -12,8 +12,14 @@ class User_options_model extends CI_Model $uid=$this->session->userdata('user_id'); $sql='insert into user_options (user_id,option_type,option_name,option_key,option_value) values (?,?,?,?,?) ON DUPLICATE KEY UPDATE option_value=?'; foreach($option_array as $option_key => $option_value) { - $query = $this->db->query($sql, array($uid, $option_type, $option_name, $option_key, $option_value, $option_value)); - } + $query = $this->db->query($sql, array($uid, $option_type, $option_name, $option_key, $option_value, $option_value)); + } + } + + public function get_options($option_type) { + $uid=$this->session->userdata('user_id'); + $sql='select option_name,option_key,option_value from user_options where user_id=? and option_type=?'; + return $this->db->query($sql, array($uid, $option_type)); } }