问:
Image upload issue with Codeigniter
I'm stuck with an issue updating images. I've created image upload which works fine but when I try to update an entry with other details which already has an image, it throws an error. Is there a way we can skip the image upload check altogether and the entry updates with or without the image?

View:

        <?php require_once("header.php"); ?>

        <?php require_once("sidebar.php"); ?>

Add Mick Chocolate

                      Chocolate
                      / Home / Add Mick Chocolate

Input

                    <?php

                        echo form_open_multipart('Admin/admin_add_image');

                    ?>

                      <form class="form-horizontal" action = "" method ="post">

                          Name

                            <input type="text" id="text1" name="chocolate_name" pattern="^[A-Za-z -]+$" required >

                          Price

                            <input type="text" id="text2" name="chocolate_price" pattern="^(0|[1-9][0-9]*)$" required >

                          Upload Image

                            <input type="file" id="text3" name="file_to_upload" accept="image/gif, image/jpeg, image/png, image/jpg">

                                <button type="submit" name="btn_add" class="btn btn-info">Add</button>
                      </form>

               <?php require_once("footer.php"); ?>

**Model**

```php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class AdminModel extends CI_Model {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function admin_register_done()
    {
        $admin_name=$this->input->post('admin_name');
        $admin_email=$this->input->post('admin_email');
        $admin_mobileno=$this->input->post('admin_mobileno');
        $admin_username=$this->input->post('admin_username');
        $admin_password=$this->input->post('admin_password');
        $data=array(
            'admin_name'=>$admin_name,
            'admin_email'=>$admin_email,
            'admin_mobileno'=>$admin_mobileno,
            'admin_username'=>$admin_username,
            'admin_password'=>$admin_password
        );
        $this->db->insert('tbl_admin_registration',$data);
    }
    public function admin_login_done()
    {
        $admin_username=$this->input->post('admin_username');
        $admin_password=$this->input->post('admin_password');
        $this->db->select('admin_username','admin_password');
        $this->db->from('tbl_admin_registration');
        $this->db->where('admin_username',$admin_username);
        $this->db->where("admin_password",$admin_password);
        return $query=$this->db->get();
    }
    public function admin_add_image_done($image)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>'http://candymart.co.in/Admin/uploads/'.$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_chocolate',$data);
    }
        public function admin_add_image_done1()
    {

        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_chocolate',$data);
    }
    public function admin_add_madhurimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_madhurchocolate',$data);
    }
    public function admin_add_crystalimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_crystalchocolate',$data);
    }
    public function admin_add_candyimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_candychocolate',$data);
    }

        public function admin_display_image_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_chocolate');
        $query=$this->db->get();
        return $query->result();
    }
        public function admin_display_madhurimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_madhurchocolate');
        $query=$this->db->get();
        return $query->result();
    }
        public function admin_display_crystalimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_crystalchocolate');
        $query=$this->db->get();
        return $query->result();
    }
       public function admin_display_candyimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_candychocolate');
        $query=$this->db->get();
        return $query->result();
    }
    public function admin_delete_image_done($id)
    {
        $this->db->where('tbl_admin_chocolate.id',$id);
        return $this->db->delete('tbl_admin_chocolate');

    }
    public function admin_delete_madhurimage_done($id)
    {
        $this->db->where('tbl_admin_madhurchocolate.id',$id);
        return $this->db->delete('tbl_admin_madhurchocolate');

    }
    public function admin_delete_crystalimage_done($id)
    {
        $this->db->where('tbl_admin_crystalchocolate.id',$id);
        return $this->db->delete('tbl_admin_crystalchocolate');

    }
        public function admin_delete_candyimage_done($id)
    {
        $this->db->where('tbl_admin_candychocolate.id',$id);
        return $this->db->delete('tbl_admin_candychocolate');

    }
    public function admin_edit_chocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_chocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_madhurchocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_madhurchocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_crystalchocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_crystalchocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_candychocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_candychocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_update_chocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>'http://candymart.co.in/Admin/uploads/'.$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_chocolate.id',$id);
        return $this->db->update('tbl_admin_chocolate',$data);
    }
        public function admin_update_madhurchocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_madhurchocolate.id',$id);
        return $this->db->update('tbl_admin_madhurchocolate',$data);
    }
        public function admin_update_crystalchocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_crystalchocolate.id',$id);
        return $this->db->update('tbl_admin_crystalchocolate',$data);
    }
        public function admin_update_candychocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_candychocolate.id',$id);
        return $this->db->update('tbl_admin_candychocolate',$data);
    }
}
</code>```

Controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Admin extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        $this->load->view('manisha_admin');
    }
    public function admin_register()
    {
        $this->load->view('admin_register');
    }
    public function admin_register_data()
    {

        $this->load->model('AdminModel');
        $this->AdminModel->admin_register_done();
        $this->load->view('admin_login');
    }
    public function admin_login()
    {
        $this->load->view('admin_login');
    }
    public function admin_login_data()
    {

        $this->load->model('AdminModel');
        $this->AdminModel->admin_login_done();
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('add_image',$data);
    }
    public function admin_add_image()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            //$image = 'http://candymart.co.in/Admin/uploads/1.JPG';
            $this->load->view('add_image');
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            //$image = $_FILES['file_to_upload']['name'];
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_image_done();

         }
    }
    public function admin_add_madhurimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_madhurimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_madhurimage_done();
         }
    }
        public function admin_add_crystalimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_crystalimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_crystalimage_done();
         }
    }
        public function admin_add_candyimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_candyimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_candyimage_done();
         }
    }
    public function admin_edit_image()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_chocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id1');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_chocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_image_done();
            $this->load->view('display_image',$data);
         }
    }
    public function admin_edit_madhurimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_madhurchocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id2');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_madhurchocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
            $this->load->view('display_madhurimage',$data);
         }
    }
    public function admin_edit_crystalimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_crystalchocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id3');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_crystalchocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
            $this->load->view('display_crystalimage',$data);

         }
    }
    public function admin_edit_candyimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_candychocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id4');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_candychocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
            $this->load->view('display_candyimage',$data);
         }
    }
    public function admin_display_image()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('display_image',$data);
    }
    public function admin_display_madhurimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
        $this->load->view('display_madhurimage',$data);
    }
    public function admin_display_crystalimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
        $this->load->view('display_crystalimage',$data);
    }
    public function admin_display_candyimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
        $this->load->view('display_candyimage',$data);
    }

    public function admin_delete_image()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_image_done($id);
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('display_image',$data);
    }
        public function admin_delete_madhurimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_madhurimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
        $this->load->view('display_madhurimage',$data);

    }
            public function admin_delete_crystalimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_crystalimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
        $this->load->view('display_crystalimage',$data);

    }
            public function admin_delete_candyimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_candyimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
        $this->load->view('display_candyimage',$data);
    }
    public function admin_edit_chocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user1']=$this->AdminModel->admin_edit_chocolate_done($id);
        $this->load->view('edit_chocolate',$data);

    }
        public function admin_edit_madhurchocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user2']=$this->AdminModel->admin_edit_madhurchocolate_done($id);
        $this->load->view('edit_madhurchocolate',$data);

    }
        public function admin_edit_crystalchocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user3']=$this->AdminModel->admin_edit_crystalchocolate_done($id);
        $this->load->view('edit_crystalchocolate',$data);

    }
        public function admin_edit_candychocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user4']=$this->AdminModel->admin_edit_candychocolate_done($id);
        $this->load->view('edit_candychocolate',$data);

    }
        public function admin_update_chocolate()
    {
        $id = $this->input->post('hidden_id1');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_chocolate_done($id);
    }
        public function admin_update_madhurchocolate()
    {
        $id = $this->input->post('hidden_id2');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_madhurchocolate_done($id);

    }
        public function admin_update_crystalchocolate()
    {
        $id = $this->input->post('hidden_id3');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_crystalchocolate_done($id);

    }
        public function admin_update_candychocolate()
    {
        $id = $this->input->post('hidden_id4');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_candychocolate_done($id);

    }
        public function admin_logout()
    {
        $user_data = $this->session->all_userdata();
        foreach ($user_data as $key => $value) {
            if ($key != 'session_id' && $key != 'ip_address' && $key != 'user_agent' && $key != 'last_activity') {
                $this->session->unset_userdata($key);
            }
        }
        $this->session->sess_destroy();
        redirect('Admin/index');
     }

}
```

答:
You may use:</p>

```<code><?php
   ....
   if($_FILES["file_name"]["name"] != "") {
       //file uploading code
   }
   ....
?>
</code>```

Title: Image upload issue with Codeigniter

Body:
I'm stuck with an issue updating images. I've created image upload which works fine but when I try to update an entry with other details which already has an image, it throws an error. Is there a way we can skip the image upload check altogether and the entry updates with or without the image?

View:

        <?php require_once("header.php"); ?>

        <?php require_once("sidebar.php"); ?>

Add Mick Chocolate

                      Chocolate
                      / Home / Add Mick Chocolate

Input

                    <?php

                        echo form_open_multipart('Admin/admin_add_image');

                    ?>

                      <form class="form-horizontal" action = "" method ="post">

                          Name

                            <input type="text" id="text1" name="chocolate_name" pattern="^[A-Za-z -]+$" required >

                          Price

                            <input type="text" id="text2" name="chocolate_price" pattern="^(0|[1-9][0-9]*)$" required >

                          Upload Image

                            <input type="file" id="text3" name="file_to_upload" accept="image/gif, image/jpeg, image/png, image/jpg">

                                <button type="submit" name="btn_add" class="btn btn-info">Add</button>
                      </form>

               <?php require_once("footer.php"); ?>

**Model**

```php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class AdminModel extends CI_Model {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function admin_register_done()
    {
        $admin_name=$this->input->post('admin_name');
        $admin_email=$this->input->post('admin_email');
        $admin_mobileno=$this->input->post('admin_mobileno');
        $admin_username=$this->input->post('admin_username');
        $admin_password=$this->input->post('admin_password');
        $data=array(
            'admin_name'=>$admin_name,
            'admin_email'=>$admin_email,
            'admin_mobileno'=>$admin_mobileno,
            'admin_username'=>$admin_username,
            'admin_password'=>$admin_password
        );
        $this->db->insert('tbl_admin_registration',$data);
    }
    public function admin_login_done()
    {
        $admin_username=$this->input->post('admin_username');
        $admin_password=$this->input->post('admin_password');
        $this->db->select('admin_username','admin_password');
        $this->db->from('tbl_admin_registration');
        $this->db->where('admin_username',$admin_username);
        $this->db->where("admin_password",$admin_password);
        return $query=$this->db->get();
    }
    public function admin_add_image_done($image)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>'http://candymart.co.in/Admin/uploads/'.$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_chocolate',$data);
    }
        public function admin_add_image_done1()
    {

        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_chocolate',$data);
    }
    public function admin_add_madhurimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_madhurchocolate',$data);
    }
    public function admin_add_crystalimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_crystalchocolate',$data);
    }
    public function admin_add_candyimage_done()
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');
        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->insert('tbl_admin_candychocolate',$data);
    }

        public function admin_display_image_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_chocolate');
        $query=$this->db->get();
        return $query->result();
    }
        public function admin_display_madhurimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_madhurchocolate');
        $query=$this->db->get();
        return $query->result();
    }
        public function admin_display_crystalimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_crystalchocolate');
        $query=$this->db->get();
        return $query->result();
    }
       public function admin_display_candyimage_done()
    {

        $this->db->select('*');
        $this->db->from('tbl_admin_candychocolate');
        $query=$this->db->get();
        return $query->result();
    }
    public function admin_delete_image_done($id)
    {
        $this->db->where('tbl_admin_chocolate.id',$id);
        return $this->db->delete('tbl_admin_chocolate');

    }
    public function admin_delete_madhurimage_done($id)
    {
        $this->db->where('tbl_admin_madhurchocolate.id',$id);
        return $this->db->delete('tbl_admin_madhurchocolate');

    }
    public function admin_delete_crystalimage_done($id)
    {
        $this->db->where('tbl_admin_crystalchocolate.id',$id);
        return $this->db->delete('tbl_admin_crystalchocolate');

    }
        public function admin_delete_candyimage_done($id)
    {
        $this->db->where('tbl_admin_candychocolate.id',$id);
        return $this->db->delete('tbl_admin_candychocolate');

    }
    public function admin_edit_chocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_chocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_madhurchocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_madhurchocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_crystalchocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_crystalchocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_edit_candychocolate_done($id)
    {
       $query = $this->db->get_where('tbl_admin_candychocolate',array('id'=>$id));
       return $query->row_array();
    }
    public function admin_update_chocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>'http://candymart.co.in/Admin/uploads/'.$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_chocolate.id',$id);
        return $this->db->update('tbl_admin_chocolate',$data);
    }
        public function admin_update_madhurchocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_madhurchocolate.id',$id);
        return $this->db->update('tbl_admin_madhurchocolate',$data);
    }
        public function admin_update_crystalchocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_crystalchocolate.id',$id);
        return $this->db->update('tbl_admin_crystalchocolate',$data);
    }
        public function admin_update_candychocolate_done($id)
    {
        $image_info = $this->upload->data();
        $chocolate_name=$this->input->post('chocolate_name');
        $chocolate_price=$this->input->post('chocolate_price');

        $data=array(
            'image_name'=>$image_info['file_name'],
            'chocolate_name'=>$chocolate_name,
            'chocolate_price'=>$chocolate_price
        );
        $this->db->set($data);
        $this->db->where('tbl_admin_candychocolate.id',$id);
        return $this->db->update('tbl_admin_candychocolate',$data);
    }
}

Controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Admin extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        $this->load->view('manisha_admin');
    }
    public function admin_register()
    {
        $this->load->view('admin_register');
    }
    public function admin_register_data()
    {

        $this->load->model('AdminModel');
        $this->AdminModel->admin_register_done();
        $this->load->view('admin_login');
    }
    public function admin_login()
    {
        $this->load->view('admin_login');
    }
    public function admin_login_data()
    {

        $this->load->model('AdminModel');
        $this->AdminModel->admin_login_done();
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('add_image',$data);
    }
    public function admin_add_image()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            //$image = 'http://candymart.co.in/Admin/uploads/1.JPG';
            $this->load->view('add_image');
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            //$image = $_FILES['file_to_upload']['name'];
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_image_done();

         }
    }
    public function admin_add_madhurimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_madhurimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_madhurimage_done();
         }
    }
        public function admin_add_crystalimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_crystalimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_crystalimage_done();
         }
    }
        public function admin_add_candyimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('add_candyimage', $error);
         }

         else {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('Upload_success', $data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_add_candyimage_done();
         }
    }
    public function admin_edit_image()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_chocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id1');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_chocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_image_done();
            $this->load->view('display_image',$data);
         }
    }
    public function admin_edit_madhurimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_madhurchocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id2');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_madhurchocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
            $this->load->view('display_madhurimage',$data);
         }
    }
    public function admin_edit_crystalimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_crystalchocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id3');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_crystalchocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
            $this->load->view('display_crystalimage',$data);

         }
    }
    public function admin_edit_candyimage()
    {
         $config['upload_path']   = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|jpeg';
         //$config['max_size']      = 100;
         //$config['max_width']     = 1024;
         //$config['max_height']    = 768;
         $this->load->library('upload', $config);

         if ( ! $this->upload->do_upload('file_to_upload')) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_candychocolate', $error);
         }

         else {
            $id = $this->input->post('hidden_id4');
            $data = array('upload_data' => $this->upload->data());
            //$this->load->view('Upload_success',$data);
            $this->load->model('AdminModel');
            $this->AdminModel->admin_update_candychocolate_done($id);
            $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
            $this->load->view('display_candyimage',$data);
         }
    }
    public function admin_display_image()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('display_image',$data);
    }
    public function admin_display_madhurimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
        $this->load->view('display_madhurimage',$data);
    }
    public function admin_display_crystalimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
        $this->load->view('display_crystalimage',$data);
    }
    public function admin_display_candyimage()
    {
        $this->load->model('AdminModel');
        $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
        $this->load->view('display_candyimage',$data);
    }

    public function admin_delete_image()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_image_done($id);
        $data['sub'] = $this->AdminModel->admin_display_image_done();
        $this->load->view('display_image',$data);
    }
        public function admin_delete_madhurimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_madhurimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_madhurimage_done();
        $this->load->view('display_madhurimage',$data);

    }
            public function admin_delete_crystalimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_crystalimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_crystalimage_done();
        $this->load->view('display_crystalimage',$data);

    }
            public function admin_delete_candyimage()
    {
        $id = $this->uri->segment(3);
        $this->load->model('AdminModel');
        $this->AdminModel->admin_delete_candyimage_done($id);
        $data['sub'] = $this->AdminModel->admin_display_candyimage_done();
        $this->load->view('display_candyimage',$data);
    }
    public function admin_edit_chocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user1']=$this->AdminModel->admin_edit_chocolate_done($id);
        $this->load->view('edit_chocolate',$data);

    }
        public function admin_edit_madhurchocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user2']=$this->AdminModel->admin_edit_madhurchocolate_done($id);
        $this->load->view('edit_madhurchocolate',$data);

    }
        public function admin_edit_crystalchocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user3']=$this->AdminModel->admin_edit_crystalchocolate_done($id);
        $this->load->view('edit_crystalchocolate',$data);

    }
        public function admin_edit_candychocolate()
    {
        $id = $this->uri->segment(3);

        $this->load->model('AdminModel');
        $data['user4']=$this->AdminModel->admin_edit_candychocolate_done($id);
        $this->load->view('edit_candychocolate',$data);

    }
        public function admin_update_chocolate()
    {
        $id = $this->input->post('hidden_id1');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_chocolate_done($id);
    }
        public function admin_update_madhurchocolate()
    {
        $id = $this->input->post('hidden_id2');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_madhurchocolate_done($id);

    }
        public function admin_update_crystalchocolate()
    {
        $id = $this->input->post('hidden_id3');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_crystalchocolate_done($id);

    }
        public function admin_update_candychocolate()
    {
        $id = $this->input->post('hidden_id4');
        $this->load->model('AdminModel');
        $this->AdminModel->admin_update_candychocolate_done($id);

    }
        public function admin_logout()
    {
        $user_data = $this->session->all_userdata();
        foreach ($user_data as $key => $value) {
            if ($key != 'session_id' && $key != 'ip_address' && $key != 'user_agent' && $key != 'last_activity') {
                $this->session->unset_userdata($key);
            }
        }
        $this->session->sess_destroy();
        redirect('Admin/index');
     }

}

Body:
You may use:

<?php
   ....
   if($_FILES["file_name"]["name"] != "") {
       //file uploading code
   }
   ....
?>


来源: stackexchange

问:
can Syncfusion.Pdf.WinForms nuget package be used for free?
Create, Read and Edit PDF file in Windows Forms using Syncfusion PDF library

Referenced url address:
https://www.nuget.org/packages/Syncfusion.Pdf.WinForms/

答:
Greetings !!!

You can download the Syncfusion.Pdf.WinForms (https://www.nuget.org/packages/Syncfusion.Pdf.WinForms/) NuGet package from nuget.org and use it for their development. But, the license message will pop up when launching the application. Because Syncfusion introduced the licensing system from v16.2.0.41 only for Syncfusion NuGet packages and evaluation setup. You also need to generate the license key (not unlock key) and register it when the launch of your application as specified in the below help documents if referring the assemblies from Syncfusion NuGet packages or from the evaluation setup.

https://help.syncfusion.com/common/essential-studio/licensing/license-key

Also, please refer to the below blog post for understanding the licensing changes introduced in Essential Studio.

https://blog.syncfusion.com/post/whats-new-in-2018-volume-2-licensing-changes-in-the-1620x-version-of-essential-studio.aspx

Refer to the below help link to know what nuget.org users to do if they don’t have a Syncfusion account.

https://help.syncfusion.com/common/essential-studio/licensing/license-key#nugetorg-users-without-a-syncfusion-account

Regards,

Vadivel Natarajan

ContentLicense: CC BY-SA 4.0


问:
How to test a data retrieval module?
I am working on a project and have a data retrieval module written on python. All it does is build a query using string manipulations and then executes the query using another module (a connection module). I want to make unit tests properly. Does anyone have any recommendations on techniques? Is mocking a proper way to do so?</p>

答:
Your code consists of a computational part (building a query string) and an interactional part, where the actual communication with the data base is performed.  If these two are combined, the code looks as follows:

```<code>def fetchData(self):
    query = ... some string building logic here
    results = ... database access using query
</code>```

In code like this, just to check the string building logic in unit-testing, you would mock the data base access (to avoid the dependency on the data base in your unit-tests for various reasons).  In the subsequent integration testing, you would then test the interaction of fetchData with the real data base.

An alternative approach is to extract the algorithmic part (the creation of the query string) into a separate method such that you can easily test this part independently.

```<code>def buildQuery(self):
    query = ... some string building logic here
    return query

def fetchData(self):
    query = self.buildQuery()
    results = ... database access using query
</code>```

This makes your unit-testing simpler, because for the testing of buildQuery you don't need to do any mocking of the data base.  Again, in integration testing you would then test the interaction of fetchData with the real data base.

Title: How to test a data retrieval module?

Body:
Your code consists of a computational part (building a query string) and an interactional part, where the actual communication with the data base is performed.  If these two are combined, the code looks as follows:

def fetchData(self):
    query = ... some string building logic here
    results = ... database access using query

In code like this, just to check the string building logic in unit-testing, you would mock the data base access (to avoid the dependency on the data base in your unit-tests for various reasons).  In the subsequent integration testing, you would then test the interaction of fetchData with the real data base.

An alternative approach is to extract the algorithmic part (the creation of the query string) into a separate method such that you can easily test this part independently.

def buildQuery(self):
    query = ... some string building logic here
    return query

def fetchData(self):
    query = self.buildQuery()
    results = ... database access using query

This makes your unit-testing simpler, because for the testing of buildQuery you don't need to do any mocking of the data base.  Again, in integration testing you would then test the interaction of fetchData with the real data base.


问:
How to check if all array values are blank in Javascript
I have an array like:

```<code>["", "", "", "1", "", ""]
</code>```

I want to alert when all the array values are blanks, i.e, when the array is like this:

```<code>["", "", "", "", "", ""]
</code>```

How can I achieve this.

答:
1) Maintain the size of array as length
2) Find the no. of empty values in the array and store it in say an variable (EmptyValues)

3) Check if (EmptyValue== length)  {  Give Alert whatever you want}

```<code>function checkBlankvalues(arr){
var emptyValues=0,length=arr.length;
//for finding empty vales in array till now
for(var i=0;i<arr.length;i++)
{
   if(arr[i]="")
   {
     emptyValues++;
   }
}
if(length==emptyValue)
{
 //alert("array is blank");
}
}
</code>```

Body:
I have an array like:

["", "", "", "1", "", ""]

I want to alert when all the array values are blanks, i.e, when the array is like this:

["", "", "", "", "", ""]

How can I achieve this.

Body:
1) Maintain the size of array as length
2) Find the no. of empty values in the array and store it in say an variable (EmptyValues)

3) Check if (EmptyValue== length)  {  Give Alert whatever you want}

function checkBlankvalues(arr){
var emptyValues=0,length=arr.length;
//for finding empty vales in array till now
for(var i=0;i<arr.length;i++)
{
   if(arr[i]="")
   {
     emptyValues++;
   }
}
if(length==emptyValue)
{
 //alert("array is blank");
}
}


问:
How to access Olap-Cubes from R on Linux
I want to access an Olap-Cube from R on Linux. Specifically I have a SQL-Server 2016 with Analysis Services and Cubes that I would like to access.

We have been accessing the cubes from R on windows using microsoft R and the olapR-package. And while there is a linux version of microsoft-R, it does not include the olapR-package.

We have installed the R-Services for our SQL-Server. And we did install the olapR package there (using the R-Server Binding), but it seems that it doesn't come with support for mrsdeploy.

What other options do I have to access the cubes from R on linux? We heard about the Revoscaler Package, but don't know how to use it on Cubes. Maybe we could post an sql-script containing r-code to the server and have the sql-server execute the r-code? I didn't find any help on this approach though.

Any help is appreciated.

答:
In our case it does work by embedding the olapR-code within T-SQL within RODBC-Code.

```<code>library(RODBC)
my_server="<server>"
my_db="<database>"
my_username="<myusername>"
my_pwd="<mypassword>"

db <- odbcDriverConnect(paste0("DRIVER={SQL Server};
                               server=",my_server,";
                               database=",my_db,";
                               uid=",my_username,";
                               pwd=",my_pwd))

sql="exec sp_execute_external_script
    @language =N'R',
    @script=N'
    library(olapR)

    cnnstr <- \"Data Source=<server>; Provider=MSOLAP; initial catalog=<AnalysisService>; User Id=<domain>\\\\<user>; Password=<myPassword>\"
    olapCnn <- OlapConnection(cnnstr)
    mdx <- \" <MDX-Query> \"
    OutputDataSet <- execute2D(olapCnn, mdx)';"

df <- sqlQuery(db,sql)
</code>```

Please note the quadruple backslash in domain\user.

Please note that the analysis services login is not necessarily the same as the SQL-login

Please note that the SQL user must have the rights to execute external scripts:

```<code>GRANT EXECUTE ANY EXTERNAL SCRIPT TO [<user>]
</code>```

It could be improved some more by using a "with result sets" statement, but it works.

Body:
In our case it does work by embedding the olapR-code within T-SQL within RODBC-Code.

library(RODBC)
my_server="<server>"
my_db="<database>"
my_username="<myusername>"
my_pwd="<mypassword>"

db <- odbcDriverConnect(paste0("DRIVER={SQL Server};
                               server=",my_server,";
                               database=",my_db,";
                               uid=",my_username,";
                               pwd=",my_pwd))

sql="exec sp_execute_external_script
    @language =N'R',
    @script=N'
    library(olapR)

    cnnstr <- \"Data Source=<server>; Provider=MSOLAP; initial catalog=<AnalysisService>; User Id=<domain>\\\\<user>; Password=<myPassword>\"
    olapCnn <- OlapConnection(cnnstr)
    mdx <- \" <MDX-Query> \"
    OutputDataSet <- execute2D(olapCnn, mdx)';"

df <- sqlQuery(db,sql)

Please note the quadruple backslash in domain\user.

Please note that the analysis services login is not necessarily the same as the SQL-login

Please note that the SQL user must have the rights to execute external scripts:

GRANT EXECUTE ANY EXTERNAL SCRIPT TO [<user>]

It could be improved some more by using a "with result sets" statement, but it works.


问:
ionic 4 ion-slider lock at the last slide
I'm developing an ionic 4 mobile app with an ion-slider that slides horizontally. the slider is working. but I couldn't stop the sliding at the last slide. I need to lock my last slide at the slider. </p>

```<code><div style="float: left; width: 100%">

    <ion-slides [options]="sliderConfig" style="width: 100%" #slides>

        <ion-slide style=" margin-left: -30%">
            <div style="float:left">
                <!-- <ion-card style="width: 180px; height: 200px;" >
                                <ion-card-content> -->
                <ion-avatar style="height: 110px;width: 110px" align="center">
                    <img src="../../../assets/f1.jpg" style="width: 100%; height:100%" />

                </ion-avatar>
                <!-- <img src="../../../assets/food.jpg" style="width:220px; height:200px"/>   -->

                <ion-label>
                    Promo
                </ion-label>
                <!-- </ion-card-content>
                            </ion-card>
          -->
            </div>

        </ion-slide>

        <ion-slide style="margin-left: -20%">
            <div style="float:left">
                <ion-avatar style="height: 110px;width: 110px" align="center">
                    <img src="../../../assets/food.jpg" style="width: 100%; height:100%" />

                </ion-avatar>
                <ion-label>
                    New
                </ion-label>
            </div>

        </ion-slide>

        <ion-slide style="width:100%; margin-left: -20%">
            <div style="float:left">
                <ion-avatar style="height: 110px;width: 110px" align="center">
                    <img src="../../../assets/sri.jpg" style="width:100%; height:100%" />

                </ion-avatar>
                <ion-label>
                    Sri Lankan
                </ion-label>
            </div>

        </ion-slide>
</code>```

<p>
</p>

答:
Please try the below code. I did some modification.

```<code><div style="float: left; width: 100%">

<ion-slides style="width: 100%" #slides>

    <ion-slide>
      <ion-card style="width: 180px; height: 200px;" >
        <ion-card-content>
            <ion-avatar style="height: 110px;width: 110px" align="center">
                <img src="https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwjavZyClMXiAhVFVH0KHcbcAu4QjRx6BAgBEAU&url=https%3A%2F%2Fwww.pexels.com%2Fsearch%2Fnature%2F&psig=AOvVaw3lI4NtiR2SsIzSprapcqzp&ust=1559371058163196" style="width: 100%; height:100%" />

            </ion-avatar>

            <ion-label>
                Promo
            </ion-label>
        </ion-card-content>
      </ion-card>

    </ion-slide>

    <ion-slide>
      <ion-card style="width: 180px; height: 200px;" >
        <ion-card-content>
            <ion-avatar style="height: 110px;width: 110px" align="center">
                <img src="https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwjavZyClMXiAhVFVH0KHcbcAu4QjRx6BAgBEAU&url=https%3A%2F%2Fwww.pexels.com%2Fsearch%2Fnature%2F&psig=AOvVaw3lI4NtiR2SsIzSprapcqzp&ust=1559371058163196" style="width: 100%; height:100%" />

            </ion-avatar>

            <ion-label>
                Promo
            </ion-label>
        </ion-card-content>
      </ion-card>

    </ion-slide>

    <ion-slide>
      <ion-card style="width: 180px; height: 200px;" >
        <ion-card-content>
            <ion-avatar style="height: 110px;width: 110px" align="center">
                <img src="https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwjavZyClMXiAhVFVH0KHcbcAu4QjRx6BAgBEAU&url=https%3A%2F%2Fwww.pexels.com%2Fsearch%2Fnature%2F&psig=AOvVaw3lI4NtiR2SsIzSprapcqzp&ust=1559371058163196" style="width: 100%; height:100%" />

            </ion-avatar>

            <ion-label>
                Promo
            </ion-label>
        </ion-card-content>
      </ion-card>

    </ion-slide>

</ion-slides>
</code>```

App Url = enter link description here

editor Url  = enter link description here

You have used margin left 25%. that is the issue i think

Body:
I'm developing an ionic 4 mobile app with an ion-slider that slides horizontally. the slider is working. but I couldn't stop the sliding at the last slide. I need to lock my last slide at the slider.

    <ion-slides [options]="sliderConfig" style="width: 100%" #slides>

        <ion-slide style=" margin-left: -30%">

                <ion-avatar style="height: 110px;width: 110px" align="center">

                </ion-avatar>

                <ion-label>
                    Promo
                </ion-label>

        </ion-slide>

        <ion-slide style="margin-left: -20%">

                <ion-avatar style="height: 110px;width: 110px" align="center">

                </ion-avatar>
                <ion-label>
                    New
                </ion-label>

        </ion-slide>

        <ion-slide style="width:100%; margin-left: -20%">

                <ion-avatar style="height: 110px;width: 110px" align="center">

                </ion-avatar>
                <ion-label>
                    Sri Lankan
                </ion-label>

        </ion-slide>

Body:
Please try the below code. I did some modification.

<div style="float: left; width: 100%">

<ion-slides style="width: 100%" #slides>

    <ion-slide>
      <ion-card style="width: 180px; height: 200px;" >
        <ion-card-content>
            <ion-avatar style="height: 110px;width: 110px" align="center">
                <img src="https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwjavZyClMXiAhVFVH0KHcbcAu4QjRx6BAgBEAU&url=https%3A%2F%2Fwww.pexels.com%2Fsearch%2Fnature%2F&psig=AOvVaw3lI4NtiR2SsIzSprapcqzp&ust=1559371058163196" style="width: 100%; height:100%" />

            </ion-avatar>

            <ion-label>
                Promo
            </ion-label>
        </ion-card-content>
      </ion-card>

    </ion-slide>

    <ion-slide>
      <ion-card style="width: 180px; height: 200px;" >
        <ion-card-content>
            <ion-avatar style="height: 110px;width: 110px" align="center">
                <img src="https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwjavZyClMXiAhVFVH0KHcbcAu4QjRx6BAgBEAU&url=https%3A%2F%2Fwww.pexels.com%2Fsearch%2Fnature%2F&psig=AOvVaw3lI4NtiR2SsIzSprapcqzp&ust=1559371058163196" style="width: 100%; height:100%" />

            </ion-avatar>

            <ion-label>
                Promo
            </ion-label>
        </ion-card-content>
      </ion-card>

    </ion-slide>

    <ion-slide>
      <ion-card style="width: 180px; height: 200px;" >
        <ion-card-content>
            <ion-avatar style="height: 110px;width: 110px" align="center">
                <img src="https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwjavZyClMXiAhVFVH0KHcbcAu4QjRx6BAgBEAU&url=https%3A%2F%2Fwww.pexels.com%2Fsearch%2Fnature%2F&psig=AOvVaw3lI4NtiR2SsIzSprapcqzp&ust=1559371058163196" style="width: 100%; height:100%" />

            </ion-avatar>

            <ion-label>
                Promo
            </ion-label>
        </ion-card-content>
      </ion-card>

    </ion-slide>

</ion-slides>

App Url = enter link description here

editor Url  = enter link description here

You have used margin left 25%. that is the issue i think


问:
Github Webhook on Local Jenkins Server
I would like to know is it possible to set a Github Webhook on Local Jenkins Server? Is there any Jenkins plugin to solve this kind of problem? Thanks.</p>

答:
In your Jenkins server, Go to “Manage Jenkins” -> “Manage Plugins” as shown below:

Search for GitHub plugin in the available list of plugins and install it, as shown below.

Next go to your GitHub project's settings, click the webhooks tab on the left as shown below and add the Jenkins GitHub plugin's webhook URL there.

Everytime, a Git pull or Git push event happens, GitHub will send a HTTP Post notification to your Jenkins server via the GitHub plugin.

You need a service like SocketXP to interconnect online GitHub or GitLab or Bitbucket project with your Jenkins server running in your local network or in your private cloud.

ContentLicense: CC BY-SA 3.0

Title: Github Webhook on Local Jenkins Server


问:
Room using the @Relation annotation - one to many relationship where clause child relationship
Using the @Relation annotation. I can query a one to many relationship using the following:

```<code> @Dao
 public interface PostDao {
        @Query("SELECT * FROM post")
        List<PostWithComments> getPostWithComments();
 }
</code>```

Here are the entities

```<code>@Entity
public class Post {
    @PrimrayKey
    private int id;
    private String title;
    private String content;
}

@Entity
public class Comment {
    @PrimrayKey
    private int id;
    private int post_id;
    private String content;
    private String status;
}

public class PostWithComments {
    @Embedded
    public Post post;

    @Relation(parentColumn = "id", entityColumn = "post_id", entity = Comment.class)
    public List<Comment> comments;

}
</code>```

I would like to get all posts that have a comment with status = approved but I'm not exactly sure how room handles this. I tried the following:

```<code> @Dao
 public interface PostDao {
        @Query("SELECT * FROM post INNER JOIN comment ON post.id = comment.post_id WHERE comment.status = 'approved'")
        List<PostWithComments> getPostWithComments();
 }
</code>```

I got duplicates in the results. Each post is there multiple times in List<PostWithComments> results.

Update:

After reading the generated code at PostDao_Impl.java it seems that Room is doing a sub query to fetch the relation.

First, it executes the query in the @Query annotation from the getPostWithComments method, and then it generates a sub query for the relation to populate List<Comment>

SELECT id, post_id, title, content FROM comment WHERE post_id IN ( and some other logic, and there doesn't seem to be a way to modify the generated sub query.

Is there another way to do this?

答:
Not tested but you can try this...</p>

```<code>public class PostWithComments {
    @Embedded
    public Post post;

    @Embedded
    public Comment comment;
}

@Dao
public interface PostWithCommentsDao {
       @Query("SELECT post.*, comment.* FROM post LEFT JOIN comment ON post.id=comment.post_id where comment.status = 'approved'")
       List<PostWithComments> getPostWithComments();
}
</code>```

Body:
Using the @Relation annotation. I can query a one to many relationship using the following:

 @Dao
 public interface PostDao {
        @Query("SELECT * FROM post")
        List<PostWithComments> getPostWithComments();
 }

Here are the entities

@Entity
public class Post {
    @PrimrayKey
    private int id;
    private String title;
    private String content;
}

@Entity
public class Comment {
    @PrimrayKey
    private int id;
    private int post_id;
    private String content;
    private String status;
}

public class PostWithComments {
    @Embedded
    public Post post;

    @Relation(parentColumn = "id", entityColumn = "post_id", entity = Comment.class)
    public List<Comment> comments;

}

I would like to get all posts that have a comment with status = approved but I'm not exactly sure how room handles this. I tried the following:

 @Dao
 public interface PostDao {
        @Query("SELECT * FROM post INNER JOIN comment ON post.id = comment.post_id WHERE comment.status = 'approved'")
        List<PostWithComments> getPostWithComments();
 }

I got duplicates in the results. Each post is there multiple times in List<PostWithComments> results.

Update:

After reading the generated code at PostDao_Impl.java it seems that Room is doing a sub query to fetch the relation.

First, it executes the query in the @Query annotation from the getPostWithComments method, and then it generates a sub query for the relation to populate List<Comment>

SELECT id, post_id, title, content FROM comment WHERE post_id IN ( and some other logic, and there doesn't seem to be a way to modify the generated sub query.

Is there another way to do this?

Body:
Not tested but you can try this...

public class PostWithComments {
    @Embedded
    public Post post;

    @Embedded
    public Comment comment;
}

@Dao
public interface PostWithCommentsDao {
       @Query("SELECT post.*, comment.* FROM post LEFT JOIN comment ON post.id=comment.post_id where comment.status = 'approved'")
       List<PostWithComments> getPostWithComments();
}


问:
What is the right import for lodash constructor?
I am working on some Angular projects and use lodash as helper. I read a lot of articles about how to import lodash the right way to make the bundle size smaller. But I got a problem with my current implementation because I use lodash chaining method.

```<code>return _(items)
  .groupBy(x => x.vote.code)
  .map(items => items)
  .value();
</code>```

```<code>import * as _ from 'lodash';
</code>```

I read import * is not good.
My problem is how can I import _(items) so that my import looks like below?

```<code>import groupBy from 'lodash/groupBy';
</code>```

答:
If you want to reduce your bundle size, you want to avoid importing the whole of Lodash. Instead, you can just import the functions you want - groupBy and map.

However, in this case you are also using chaining, which does require all of Lodash. You can re-write your code using flow and use the functional programming-friendly bundle of Lodash to replace  the chaining:

```<code>import {flow, groupBy, map} from 'lodash/fp';

/* ... */

const chainReplacement = flow(groupBy(x => x.vote.code), map(items => items));
return chainReplacement(items)
</code>```

Here is a quick illustration that the two produce equivalent results:

const {flow, groupBy, map} = _;

//sample data
const items = [
  { vote: { code: "1" }, name: "Alice"},
  { vote: { code: "2" }, name: "Bob"},
  { vote: { code: "1" }, name: "Carol"},
  { vote: { code: "2" }, name: "Dave"},
  { vote: { code: "1" }, name: "Edel"}
];

//using literally the same functions
const groupByCallback = x => x.vote.code;
const mapCallback = items => items.length;

const chain = _(items)
  .groupBy(groupByCallback)
  .map(mapCallback);

const chainReplacement = flow(
  groupBy(groupByCallback),
  map(mapCallback)
);

console.log("chain", chain.value())
console.log("chainReplacement", chainReplacement(items))```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/lodash-fp/0.10.4/lodash-fp.min.js"></script></code>```

I made some data that matched your usage of groupBy but then had to modify the map callback because it didn't make sense. I assume because it was for illustrative purposes. So I swapped it for items => items.length to get the count of each group. It's not very meaningful but it's also for illustrative purpose only.

Body:
I am working on some Angular projects and use lodash as helper. I read a lot of articles about how to import lodash the right way to make the bundle size smaller. But I got a problem with my current implementation because I use lodash chaining method.

return _(items)
  .groupBy(x => x.vote.code)
  .map(items => items)
  .value();

import * as _ from 'lodash';

I read import * is not good.
My problem is how can I import _(items) so that my import looks like below?

import groupBy from 'lodash/groupBy';

Body:
If you want to reduce your bundle size, you want to avoid importing the whole of Lodash. Instead, you can just import the functions you want - groupBy and map.

However, in this case you are also using chaining, which does require all of Lodash. You can re-write your code using flow and use the functional programming-friendly bundle of Lodash to replace  the chaining:

import {flow, groupBy, map} from 'lodash/fp';

/* ... */

const chainReplacement = flow(groupBy(x => x.vote.code), map(items => items));
return chainReplacement(items)

Here is a quick illustration that the two produce equivalent results:

const {flow, groupBy, map} = _;

//sample data
const items = [
  { vote: { code: "1" }, name: "Alice"},
  { vote: { code: "2" }, name: "Bob"},
  { vote: { code: "1" }, name: "Carol"},
  { vote: { code: "2" }, name: "Dave"},
  { vote: { code: "1" }, name: "Edel"}
];

//using literally the same functions
const groupByCallback = x => x.vote.code;
const mapCallback = items => items.length;

const chain = _(items)
  .groupBy(groupByCallback)
  .map(mapCallback);

const chainReplacement = flow(
  groupBy(groupByCallback),
  map(mapCallback)
);

console.log("chain", chain.value())
console.log("chainReplacement", chainReplacement(items))

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash-fp/0.10.4/lodash-fp.min.js"></script>

I made some data that matched your usage of groupBy but then had to modify the map callback because it didn't make sense. I assume because it was for illustrative purposes. So I swapped it for items => items.length to get the count of each group. It's not very meaningful but it's also for illustrative purpose only.


问:
Show 404 Not found for Query strings with pattern site.com/?xyz
I have wordpress site issue with spam in google indexed in format site.com/?xyz, site.com/?etc;
I searched for showing 404 Not found for these query strings with this code in htaccess:

```<code>RewriteEngine on
RewriteCond %{QUERY_STRING} .
RewriteRule (.*) /404.php? [L,R=404]
</code>```

The problem is that this code turns every query string in URL to 404 not found no matter it locates on site.com/?blabla or site.com/page1/?blablabla; what i want is that 404 Not found for just site.com/? strings, and no other query string should be effected. Please help to modify the code. With the above code wordpress theme, plugins and ads loading are affected.

答:
Try this:</p>

```<code>RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(\/)?$ /404.php? [L,R=404]
</code>```

Body:
I have wordpress site issue with spam in google indexed in format site.com/?xyz, site.com/?etc;
I searched for showing 404 Not found for these query strings with this code in htaccess:

RewriteEngine on
RewriteCond %{QUERY_STRING} .
RewriteRule (.*) /404.php? [L,R=404]

The problem is that this code turns every query string in URL to 404 not found no matter it locates on site.com/?blabla or site.com/page1/?blablabla; what i want is that 404 Not found for just site.com/? strings, and no other query string should be effected. Please help to modify the code. With the above code wordpress theme, plugins and ads loading are affected.

Body:
Try this:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(\/)?$ /404.php? [L,R=404]


问:
Wordpress query returning posts with very old date when querying for future events
I'm doing a wordpress query for future events based on the date code stored in a meta value. I'm getting the future events as expected but some very old events from the 1990s are being returned in the query after the future events. Is there any way around this?

```<code>$today = time();

$futureloop = new WP_Query( array(
'post_type' => 'exhibitions',
'post_status' => 'publish',
'posts_per_page' => '100',
'meta_query' => array(
 array(
  'key' => 'exhibition_date',
  'compare' => '>=',
  'value' => $today,
 )
),
'meta_key' => 'exhibition_date',
'orderby' => 'meta_value',
'order' => 'ASC'
) );
while ( $futureloop->have_posts() ) : $futureloop->the_post();
</code>```

For example I have one event that occurred in April 1990 that is showing up.
When I echo $today and the date of the event this is the result:

639273600 $exhibiton_date

1559283337 $today

答:
It seems exhibition_date is DATETIME type. So you should try meta_query as below.

```<code>$today= date('Y-m-d H:i:s');

'meta_query' => array(
 array(
  'key' => 'exhibition_date',
  'value' => $today,
  'compare' => '<=',
  'type'      => 'DATETIME',
 )
),
</code>```

Hope it will work for you.

Class Reference/WP Meta Query

Body:
I'm doing a wordpress query for future events based on the date code stored in a meta value. I'm getting the future events as expected but some very old events from the 1990s are being returned in the query after the future events. Is there any way around this?

$today = time();

$futureloop = new WP_Query( array(
'post_type' => 'exhibitions',
'post_status' => 'publish',
'posts_per_page' => '100',
'meta_query' => array(
 array(
  'key' => 'exhibition_date',
  'compare' => '>=',
  'value' => $today,
 )
),
'meta_key' => 'exhibition_date',
'orderby' => 'meta_value',
'order' => 'ASC'
) );
while ( $futureloop->have_posts() ) : $futureloop->the_post();

For example I have one event that occurred in April 1990 that is showing up.
When I echo $today and the date of the event this is the result:

639273600 $exhibiton_date

1559283337 $today

Body:
It seems exhibition_date is DATETIME type. So you should try meta_query as below.

$today= date('Y-m-d H:i:s');

'meta_query' => array(
 array(
  'key' => 'exhibition_date',
  'value' => $today,
  'compare' => '<=',
  'type'      => 'DATETIME',
 )
),

Hope it will work for you.

Class Reference/WP Meta Query


问:
How do I update the password for Git?
I'm using BitBucket with Xcode and Git for version control, and recently I changed all of my passwords (thanks Adobe!).

Unsurprisingly, I'm no longer able to push my local commits to my repository on BitBucket (Authentication failed for 'https://______.git'), but I'm forgetting how to update the cached password on my iMac. Somehow I've been unable to find it on Google or Stack Overflow, though it seems to me it should be rather straightforward...

答:
Following steps can resolve the issue .....

Go to the folder ~/Library/Application Support/SourceTree

Delete the file {Username}@STAuth-bitbucket.org

Restart Sourcetree

Try to fetch, password filed appear, give your new password

Also can run git fetch command in terminal and need to type password

Done

Title: How do I update the password for Git?


问:
Python - Why wont wildcard bits work here?
So I am trying to put wildcard bits in a path to a network folder. The path is here:

```<code>r"\\10.180.22.211\\Data\\DS~109803~Company~name of site\\Database"
</code>```

The part between DATA and Database changes, but the rest of the path stays the exact same.  So when I actually put the entire path in, it works just fine, but if I try and change the middle part to wildcard bits it does not work.

```<code>r"\\10.180.22.211\\Data\\*\\Database"
</code>```

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: "\\10.180.22.211\\Data\\*\\Database"

I have tried , '', **, DS~*, 109803, and several other combinations, and NONE of them with wildcard bits work at all. Can someone explain why they wont work and if there is a way to make wildcard bits work in this situation?

Edit:

Here is more of my code:

```<code>import os, shutil
import glob

ip = "10.180.22.211"
#ip = input("Input your IP: ")

directorya = r"\\10.180.22.211\\Jobdata\\*\\Database"
#directorya = r"\\10.180.22.211\\Jobdata\\DS~109803000~customer~job site\\Database"
directoryb = "C:\\Users\\user\\Desktop\\test"

files = [file for file in os.listdir(directorya) if os.path.isfile(os.path.join(directorya, file))]
newest = max(glob.iglob(directorya + '\\*.*'), key=os.path.getctime)
print(newest)
shutil.copy(os.path.join(directorya, newest), directoryb)
</code>```

答:
you have two ways:

use list dir:

```<code>for filename in os.listdir(path):
    ......
</code>```

or use glob:

```<code>import glob
path = "\10.180.22.211\Data\*\Database"
for filename in glob.glob(path):
    ....
</code>```

get newest file:

```<code>    list_of_files = glob.glob('/path/to/folder/*')
    newest = max(list_of_files, key=os.path.getctime)
    print newest
</code>```

Body:
So I am trying to put wildcard bits in a path to a network folder. The path is here:

r"\\10.180.22.211\\Data\\DS~109803~Company~name of site\\Database"

The part between DATA and Database changes, but the rest of the path stays the exact same.  So when I actually put the entire path in, it works just fine, but if I try and change the middle part to wildcard bits it does not work.

r"\\10.180.22.211\\Data\\*\\Database"

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: "\\10.180.22.211\\Data\\*\\Database"

I have tried , '', **, DS~*, 109803, and several other combinations, and NONE of them with wildcard bits work at all. Can someone explain why they wont work and if there is a way to make wildcard bits work in this situation?

Edit:

Here is more of my code:

import os, shutil
import glob

ip = "10.180.22.211"
#ip = input("Input your IP: ")

directorya = r"\\10.180.22.211\\Jobdata\\*\\Database"
#directorya = r"\\10.180.22.211\\Jobdata\\DS~109803000~customer~job site\\Database"
directoryb = "C:\\Users\\user\\Desktop\\test"

files = [file for file in os.listdir(directorya) if os.path.isfile(os.path.join(directorya, file))]
newest = max(glob.iglob(directorya + '\\*.*'), key=os.path.getctime)
print(newest)
shutil.copy(os.path.join(directorya, newest), directoryb)

Body:
you have two ways:

use list dir:

for filename in os.listdir(path):
    ......

or use glob:

import glob
path = "\10.180.22.211\Data\*\Database"
for filename in glob.glob(path):
    ....

get newest file:

    list_of_files = glob.glob('/path/to/folder/*')
    newest = max(list_of_files, key=os.path.getctime)
    print newest


问:
How to search by 2 parameters at the same moment using UISearchBar
I'm using a UISearchBar for searching users. User has a username and displayname. Now I use this code for searching by parameter "username", how to search by "displayname" too, at the same moment? Search result should contains both parameters</p>

```<code>var timer: Timer?
var filteredUsers = [User]()
var users = [User]()
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
    timer?.invalidate()
    timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: false, block: { [weak self] (timer) in
        if searchText.isEmpty {
            self?.filteredUsers = (self?.users)!
        } else {
            self?.filteredUsers = (self?.users.filter { (user) -> Bool in
                return user.username.lowercased().contains(searchText.lowercased())
                })!
        }
        self?.tableView?.reloadData()
    })
}
</code>```

答:
When filtering your users, you just need to include both conditions for your check using the 'or' logical operator. Make your filtered results look something like this:</p>

```<code>self?.filteredUsers = (self?.users.filter { (user) -> Bool in
    return (
        user.username.lowercased().contains(searchText.lowercased()) ||
        user.displayname.lowercased().contains(searchText.lowercased())
    )
})!
</code>```

Body:
I'm using a UISearchBar for searching users. User has a username and displayname. Now I use this code for searching by parameter "username", how to search by "displayname" too, at the same moment? Search result should contains both parameters

var timer: Timer?
var filteredUsers = [User]()
var users = [User]()
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
    timer?.invalidate()
    timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: false, block: { [weak self] (timer) in
        if searchText.isEmpty {
            self?.filteredUsers = (self?.users)!
        } else {
            self?.filteredUsers = (self?.users.filter { (user) -> Bool in
                return user.username.lowercased().contains(searchText.lowercased())
                })!
        }
        self?.tableView?.reloadData()
    })
}

Body:
When filtering your users, you just need to include both conditions for your check using the 'or' logical operator. Make your filtered results look something like this:

self?.filteredUsers = (self?.users.filter { (user) -> Bool in
    return (
        user.username.lowercased().contains(searchText.lowercased()) ||
        user.displayname.lowercased().contains(searchText.lowercased())
    )
})!