-1

I have a form in which I display numbers of company with checkbox. User checked these company and save this in a database table. Now I want to make an update form where I want that when data retrieve from database the checkbox is already checked in list which is checked by user while entering data.

Basically i want that when user fetches his stored results from database, he should be able to see which checkbox's he ticked earlier.

Screenshot of values which is saved by user

[![enter image description here][1]][1]

List of that values which is save in select_fi columns

[![enter image description here][2]][2]

sunny
  • 1,511
  • 5
  • 20
  • 57
  • Questions seeking debugging help ("**why isn't this code working?**") must include the desired behavior, a *specific problem or error* and *the shortest code necessary* to reproduce it **in the question itself**. Questions without **a clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Praveen Kumar Purushothaman Jun 28 '16 at 07:37
  • @PraveenKumar I have no idea how i can do it i just want a way of how i can do it? – sunny Jun 28 '16 at 07:38
  • At least you could show your database structure. What have you tried to approach the problem? – Praveen Kumar Purushothaman Jun 28 '16 at 07:51
  • @PraveenKumar i update my question – sunny Jun 28 '16 at 07:57
  • Mate, still no structure is there. You have shown the contents. – Praveen Kumar Purushothaman Jun 28 '16 at 08:43
  • It would be better practice to create another table and store the list in this table than to store the selection as a comma-separated list. Please read [Is storing a delimited list in a database column really that bad?](http://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad) for more information on how and why. – Matt Raines Jun 28 '16 at 08:47

2 Answers2

1

When you fetch the current user's select_fi previously checked boxes (e.g. 1,2,3 ) you can convert it to PHP array with $current_user_checked_boxes_ids = explode(",",$string).

And then, inside the PHP loop you have to print the checkboxes in HTMLyou can write something like:

if (in_array(
$current_check_box_id, 
$current_user_checkboxes_ids))
echo '<input type="checkbox" checked="checked">';
else
echo '<input type="checkbox">';
Fredster
  • 776
  • 1
  • 6
  • 16
0

maybe like :

<?php
 $sql=select * from table;
 while($row=mysql_fetch_array($sql)){
 if($row['column1']!=''){
 ?>
  use the html code to mark the  checkbox
 <?php
}else{
 ?>
 use the html code to show checkbox without mark
<?php
}
?>
J. Zend
  • 88
  • 7