Welcome Guest, Not a member yet? Register   Sign In
Is it possible to generate dynamic form_radio ?
#1

[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.




Theme © iAndrew 2016 - Forum software by © MyBB