简体   繁体   中英

Codeigniter :How to pass search term in redirect

i have made a simple project with codeigniter using PHP and MySQL. The project gives the abillity to th user to manage his warehouse by adding new product and updating the stock of each one. Now when the user searches for a product and updates the stock value, the app updates the database and refreshes the page and showing all the products. Is there a way to pass the search term he used or even better the product that he changed in the redirect. Thanks a lot.

function prevazia($param1 = '', $param2 = '', $param3 = '')
    {
        if ($this->session->userdata('admin_login') != 1)
            redirect(base_url() . 'index.php?login');
        if ($param1 == 'edit') 
        {
            $data['type']    = $this->input->post('type');   
            $data['color']   = $this->input->post('color');
            $addition   = $this->input->post('addition');
            $data['stock']   = $this->input->post('stock') + $addition;
            $data['stock_alert']   = $this->input->post('stock_alert');
            //-----------------------------------------
            include('dbc.php');
            mysqli_query($conn,"SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
            $sql9 = "SELECT * FROM prevazia_log order by id desc LIMIT 1";          
            $result = mysqli_query($conn, $sql9);
            if ($result->num_rows > 0) 
            {
                while($row = $result->fetch_assoc()) 
                {
                    $last_id=$row['id']+1;
                }
            }
            date_default_timezone_set('Europe/Athens');
            //$result6 =  mysqli_query($conn, $sql);
            //$additionDate = DateTime::createFromFormat('d/m/Y H:i');
            //$myAdditionDate = $additionDate->format('Y-m-d H:i');
            $log['id']                  = $last_id;
            $log['user']                = $this->session->userdata('name');
            $log['create_timestamp']    = date("d-m-y  h:i:sa");
            $log['type']                = $this->input->post('type');
            $log['color']               = $this->input->post('color');
            $log['previous_stock']      = $this->input->post('stock');
            $log['addition']            = $this->input->post('addition');
            $log['new_stock']           = $this->input->post('stock') + $this->input->post('addition');
            //--------------------
            //$data['role']   = $this->input->post('role');
            $this->db->insert('prevazia_log', $log);
            $this->db->where('id', $param2);
            $this->db->update('prevazia', $data);
            // UPLOAD IMAGE FILE
            $this->session->set_flashdata('flash_message', translate('informations_updated'));
            redirect(base_url() . 'index.php?admin/prevazia', 'refresh');
        }
        if ($param1 == 'delete') 
        {
            $this->db->where('id', $param2);
            $this->db->delete('prevazia');
            $this->session->set_flashdata('flash_message', translate('data_deleted'));
            redirect(base_url() . 'index.php?admin/prevazia', 'refresh');
        }
        $page_data['page_name']  = 'prevazia';
        $page_data['page_title'] = 'Πρεβάζια';
        $page_data['prevazia']  = $this->db->get_where('prevazia', array('active'=> $GLOBALS['flag']))->result_array();
        $this->load->view('backend/index', $page_data);
    }

EDIT : the best would be if i could pass the $data['type'] and $data['color'], so when it redirects it will pass these values to the search box.

You should return the search param via view,if you are using form submit with method post

$data['search_param'] =  $post['search_param'];
$this->load->view('view_page', $data);

<input name="search_param"  value="<?php echo !empty($search_param) ? $search_param : ''?>">

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