Wednesday, February 2, 2022

[FIXED] how to show check box list with some selected value from database in codeigniter

Issue

I am new at codeigniter I have to show the check box list from database and show some check box selected which is previously selected in database.

I tried this this is my controller

$data['veddingPlanData'] = $this->PlanModel->getPlanById($planId);
$data['veddingPlanTaskMappingData'] = $this->PlanModel->getPlanAndTaskMappingByPlanId($planId);
$data['allVedingTasks'] = $this->VeddingTaskModel->getAllVeddingTask();

$this->load->view('plan_update', $data);

now how I should fetch the data or how to foreach that...????


Solution

Simply You have to create an array and and then foreach it in loop...

create and array like

<?php
$arrSelVedTask = array();
 foreach ($veddingPlanTaskMappingData as $row) { 
$arrSelVedTask[$row->your field] = '';
 }

?>

and create loop like this

<?php foreach ($allVedingTasks as $row) { 

    if(isset($arrSelVedTask[$row->your field])) 
    {
    your check box with selected value  
    }
    else
    {
        check box with out check box value
    }
 }  
    ?>


Answered By - ankit suthar

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.