Such a cat definitely requires optimization. CodeIgniter 1/7/2

$i1['category'] = $this->input->post('category'); $i1['title'] = $this->input->post('title'); $i1['fncmat'] = $this->input->post('fncmat'); $i1['fnccat'] = $this->input->post('fnccat'); $i1['description'] = $this->input->post('description'); $i1['twitter'] = $this->input->post('twitter'); $i1['rss'] = $this->input->post('rss'); $i1['sitemap'] = $this->input->post('sitemap'); $i1['control_image'] = $this->input->post('control_image'); $i1['control_comments_list'] = $this->input->post('control_comments_list'); $i1['control_twitter'] = $this->input->post('control_twitter'); $i1['control_public'] = $this->input->post('control_public'); $i1['control_aggregators'] = $this->input->post('control_aggregators'); $i1['control_notify'] = $this->input->post('control_notify'); $i1['control_comments_allow'] = $this->input->post('control_comments_allow'); $i1['control_mailer'] = $this->input->post('control_mailer'); 

The array $ i1 will update the fields in the database

  • one
    It looks something like - here's a stable for you, fuck up ... <br> But seriously - the cited code is not particularly optimizable, or do you have to enter the optimization of the query itself? - Zowie

2 answers 2

What prevents you from getting all the post request data?

 $post_recv = $this->input->post(); // returns all POST items with XSS filter 

I think, to see that in this method returns is not difficult?

And then, I suspect that you can use the following construction for the cycle:

 foreach($post_reqv as $key => $value)... 
  • Personally, I don’t understand the question at all ... - Zowie
  • But Dex is understandable, and he correctly answered the question. It is necessary to check what is returned with var_dump ($ post_recv) and immediately send the package to the array for the database. And you AlexWindHope apparently newbie still the same. - jfjgjkslxd
  • boolean false. The fact is that the return of the array was made in version 2.0.2, and I'm on the old 1.7.2 - jfjgjkslxd
  • @Increazon! [] [1] [1]: img.playground.ru/images/7/8/okay-face.jpg - Zowie

Well, since your input fields match, then the easiest way:

 $global_post = $this->input->post(); $id = 1; foreach ($global_post as $key => $value) $this->db->update('table', array($key => $value), 'id = '.$id); 
  • one
    Sir, your code is disgusting, if I understand correctly what it is doing. 1. 5 fields have arrived - we make 5 updates, why we feel sorry for chtoli. 2. The id field has arrived, updating it without any questions! we trust the user. in my opinion it’s better to do this: $ global_post = $ this-> input-> post (); $ id = 1; $ fields = array ('name', 'time', 'date', 'product', 'profile', 'filial', 'article'); $ values ​​= array (); foreach ($ global_post $ key => $ value) if (in_array ($ key, $ fields) $ values ​​[$ key] => $ value; $ this-> db-> update ('table', $ values, ' id = '. $ id); - MuFF
  • it was possible in my version to add an excluding condition on the id field, or to those fields that are needed, but your version is better, I agree, it is improved! Thanks for the criticism!) - Epexa