• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Filling and array foreach loop

#1
[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

#2
[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>

#3
[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'


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.