CodeIgniter Forums
Is it possible to generate dynamic form_radio ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Is it possible to generate dynamic form_radio ? (/thread-47624.html)



Is it possible to generate dynamic form_radio ? - El Forum - 12-15-2011

[eluser]Unknown[/eluser]
Hello, I am trying to generate multiple forms in one submit. For example, I have a table with information about games on any sport, these are the fields (gameID, weekNum, gameTime, homeID, homeScore, visitorID, visitorScore). I want to use this table to generate the forms.

Inside my view I am trying to generate the forms dynamically using the above mentioned table, so the selected team can be submitted to another results table.

I am doing this in my view:
Code:
<div id="games_form">

&lt;? foreach($games as $row) { ?&gt;
&lt;? echo form_open('games/submit'); ?&gt;
<p>&lt;? echo form_radio('game_result', 'accept', FALSE);?&gt;&lt;? echo $row->homeID ;?&gt;</p>
<p>&lt;? echo form_radio('game_result', 'accept', FALSE);?&gt;&lt;? echo $row->visitorID ;?&gt;</p>
&lt;? echo '<hr/>'; ?&gt;
&lt;? } ?&gt;
&lt;? echo form_submit('mysubmit', 'submit'); ?&gt;
</div>

The problem with this approach is that I am just able to select one team from the list, instead one for every game.

This is my games_model
Code:
//retrieve all games
function get_all(){
  return $this->db->get('nflp_schedule');
}

This is my games controller, I am filtering the games by week with another function.
Code:
class Games extends CI_Controller {

function __construct(){
  parent::__construct();
  $this->load->model('games_model');
  $this->load->helper('url');
  $this->load->library('table');
  $this->load->helper('form');
}

function index(){
  $data['title'] = "Games forecast";
  $data['headline'] = "Games List";
  $data['include'] = 'games_list';
  $data['weeks'] = $this->games_model->get_weeks();
  
  $query_weeks = $this->games_model->get_all();
  $data['games_table'] = $this->table->generate($query_weeks);
  
  
  $this->load->view('template', $data);
}

function week(){
  $data['games'] = $this->games_model->get_by_week($this->uri->segment(3));
  $data['title'] = "Games forecast";
  $data['headline'] = "Games List";
  $data['include'] = "games_list";
  $data['weeks'] = $this->games_model->get_weeks();
  
  $this->load->model('games_model');
  
  $this->load->view('template', $data);
}

}

I will appreciate any comments or help. Thanks in advanced.