[eluser]Jacek Dominiak[/eluser]
Hello all,
It's my first post here as I am stuck in a dead point (possible lack of knowledge from my side). I tried various ways and just can't get it run. As for a person which just started with CI, please be gentle ;P
I have 2 tables:
1. pairs (list of all values and it's comments).
2. user_pairs defined by user to reuse later on within the application.
Here are concerned
- model functions:
Code:
function get_all_pairs()
{
$q = $this->db->get('pairs');
return $q->result();
}
function get_user_pairs($uid)
{
$this->db->select('pair');
$q = $this->db->get_where('user_pairs', array('uid' => $uid));
return $q->result();
}
- controler:
Code:
function list_user_pairs()
{
if($this->dx_auth->is_logged_in())
{
$uid = $this->dx_auth->get_user_id();
$uname = $this->dx_auth->get_username();
$data['user_selected'] = $this->settings_model->get_user_pairs($uid);
$data['pairs'] = $this->settings_model->get_all_pairs();
$data['main_content'] = 'settings/list_pairs';
$data['uname'] = $uname;
$this->load->view('theme/template', $data);
}
else
{
redirect('auth/login');
}
}
- view:
Code:
echo form_open('settings/pair_save');
echo '<div id="content">';
$array = (array) $user_selected;
echo '<br />';
foreach($pairs as $pair){
if (in_array($pair->pair, $array))
{
$data = array(
'name' => $pair->pair,
'id' => $pair->pid,
'value' => 'accept',
'checked' => TRUE,
'style' => 'margin: 10px; ',);
}
else
{
$data = array(
'name' => $pair->pair,
'id' => $pair->pid,
'value' => 'accept',
'checked' => FALSE,
'style' => 'margin: 10px; ',);
}
echo '<p>' .form_checkbox($data), $pair->pair. ' <h4>' .$pair->comment. '</h4></p><br />';
}
echo form_submit('save_pairs', 'Save');
echo form_close();
My problem here is that I try to check if there are any user pairs in order to display them as checked.
No believe it's a problem with string to array convention... but dunno where to go from here
I would really appreciate any help.