error displaying values got from an array
<p>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 </p>

<p>view file:</p>

<pre><code>&lt;input type="checkbox" name="options" id="options" value="&lt;?php echo $row-&gt;slNo?&gt;"&gt;
&lt;input type="checkbox" id="selectAll" name="selectAll" /&gt;
</code></pre>

<p>js:</p>

<pre><code>$('#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();
          });

          }
});
</code></pre>

<p>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</p>

<p>view file:</p>

<pre><code>&lt;input type="hidden" id="getrolevalues"&gt;
</code></pre>

<p>js:</p>

<pre><code>$("#submit").click(function(){

          var js=$('#getrolevalues').val();
      $.post(url+"/roles/tabledata",{"gotoption":js},function(data){
          $('#roleschk').html(data.result);

},"json");
</code></pre>

<p>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</p>

<p>controller:</p>

<pre><code>function tabledata()
    {
         echo $data=$this-&gt;input-&gt;post('gotoption');
         $pieces = explode( ",", $data);
        //echo $pieces[1];
        //echo $e=count($pieces);
        $sql=array();
    for($i = 0; $i&lt; count($pieces); $i++)
    { 
        $piec= $pieces[$i];
        $sql[]=$this-&gt;rolesmodel-&gt;roleselect($piec);
    }
    $sql['dipl']=$sql;

        $slr=$this-&gt;load-&gt;view('roleschecked',$sql,true);
        $value=array(
            'result'=&gt;$slr
        );
        echo json_encode($value);
}
</code></pre>

<p>model:</p>

<pre><code>function roleselect($piec)
    {
        /*for($i = 0; $i&lt; count($pieces); $i++)
        { */
        echo $chkroles="SELECT * FROM dummyroles WHERE slNo='$piec'";

        $qry=$this-&gt;db-&gt;query($chkroles);
//      }

        return $qry;
    }
</code></pre>

<p>also the roleschecked view file where i display the results:</p>

<pre><code>&lt;p&gt;You Have selected the following persons&lt;/p&gt;
&lt;table border=2&gt;
&lt;tr&gt;
&lt;th&gt;Sl.No&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Roles&lt;/th&gt;
&lt;/tr&gt;
&lt;?php foreach($dipl as $row)
{?&gt;
&lt;tr&gt;
&lt;td&gt;&lt;?php echo $row()-&gt;slNo[0]?&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?php }?&gt;
&lt;/table&gt;
</code></pre>

<p>the problem now is that only last value i get when i use like this in controller</p>

<pre><code>.........
.........
$sql['dipl']=$this-&gt;rolesmodel-&gt;roleselect($piec);
.........
</code></pre>

<p>and if i use like this i get an error</p>

<pre><code>.........
$sql[]=$this-&gt;rolesmodel-&gt;roleselect($piec);
.............
$sql['dipl']=$sql;
</code></pre>

<p>please help me with this issue</p>
