I have a database table from which i am getting values and displaying it in a view page.Then the admin will click on the checkbox next to each row in the table.On click of each checkbox i will get the value of that checkbox.the code(view file and js) for it is this one
view file:
<input type="checkbox" name="options" id="options" value="<?php echo $row->slNo?>">
<input type="checkbox" id="selectAll" name="selectAll" />
js:
$('#selectAll').change(function(){
if($(this).attr('checked'))
{
$('[name=options]').attr('checked',true);
function updateTextArea()
{
var allVals = $('#rrol :checked').map(function()
{
return $(this).val();
}).get();
$('#getrolevalues').val(allVals);
}
$(function()
{
$('#rrol input').click(updateTextArea);
updateTextArea();
});
}
else
{
$('[name=options]').attr('checked',false);
function updateTextArea()
{
var allVals = $('#rrol :checked').map(function()
{
return $(this).val();
}).get();
$('#getrolevalues').val(allVals);
}
$(function()
{
$('#rrol input').click(updateTextArea);
updateTextArea();
});
}
});
I have saved the values that i got in a hidden text box and im sending it to the controller.code( view file and js) for it is below
view file:
<input type="hidden" id="getrolevalues">
js:
$("#submit").click(function(){
var js=$('#getrolevalues').val();
$.post(url+"/roles/tabledata",{"gotoption":js},function(data){
$('#roleschk').html(data.result);
},"json");
so far everything is working fine.but after sending the values which i have stored in an array im getting an error.i.e in controller i get the array values and then i use explode function to separate each value.then i use for loop to send those values to model and get the values and display the result.the code is below
controller:
function tabledata()
{
echo $data=$this->input->post('gotoption');
$pieces = explode( ",", $data);
//echo $pieces[1];
//echo $e=count($pieces);
$sql=array();
for($i = 0; $i< count($pieces); $i++)
{
$piec= $pieces[$i];
$sql[]=$this->rolesmodel->roleselect($piec);
}
$sql['dipl']=$sql;
$slr=$this->load->view('roleschecked',$sql,true);
$value=array(
'result'=>$slr
);
echo json_encode($value);
}
model:
function roleselect($piec)
{
/*for($i = 0; $i< count($pieces); $i++)
{ */
echo $chkroles="SELECT * FROM dummyroles WHERE slNo='$piec'";
$qry=$this->db->query($chkroles);
// }
return $qry;
}
also the roleschecked view file where i display the results:
<p>You Have selected the following persons</p>
<table border=2>
<tr>
<th>Sl.No</th>
<th>Name</th>
<th>Roles</th>
</tr>
<?php foreach($dipl as $row)
{?>
<tr>
<td><?php echo $row()->slNo[0]?></td>
</tr>
<?php }?>
</table>
the problem now is that only last value i get when i use like this in controller
.........
.........
$sql['dipl']=$this->rolesmodel->roleselect($piec);
.........
and if i use like this i get an error
.........
$sql[]=$this->rolesmodel->roleselect($piec);
.............
$sql['dipl']=$sql;
please help me with this issue