CodeIgniter Forums
Filling and array foreach loop - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Filling and array foreach loop (/showthread.php?tid=39204)



Filling and array foreach loop - El Forum - 03-04-2011

[eluser]Michal1[/eluser]
Hello guys,

I have been working on one script and I am stuck at filling my array. What I have in my view is this code

Code:
$backlinkSources = array ();

foreach ($backlinkSources as $roww) {
    
    



$backlinkSources = array (
    'name_thems'=>$roww->name_them,
                          
                         );
                        
                        
                        
                         }

Then in my one controller function I have this array

Code:
$data = array(
            
            'name_them'=>$this->input->post('name_them')
            
                );
                
                $this->site_model->insert_data($data);

And basically what I want to do is to take that name_them in my site_view and pass it into that name_thems field
Code:
array $backlinkSources = array (
    'name_thems'=>  something

But it does not work. Does somebody know what am I doing wrong? Please answer me as easy as possible as I am a beginner.

Thank you


Filling and array foreach loop - El Forum - 03-04-2011

[eluser]Wondering Coder[/eluser]
is this what you want

Your controller

Code:
function insert(){
....
$data = array(
            'name_them'=>$this->input->post('name_them')
            
                );
                $this->site_model->insert_data($data);
}
Your model
Code:
function insert_data($data){
$this->db->insert('tablename',$data);}

View
Code:
<form method="post" action="<?=base_url()?>controller_name/insert">
<input type="text" name="name_them">
</form>



Filling and array foreach loop - El Forum - 03-04-2011

[eluser]Michal1[/eluser]
No Smile

I want to fill this array
Code:
$backlinkSources = array ();
in my view

with everything from
Code:
$data = array(
            
            'name_them'