PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 2, 2022

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

 February 02, 2022     codeigniter, foreach, mysql, php, phpmyadmin     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing