Jump to content

php checked checkbox values


An7hony

Recommended Posts

Below is an example of how the script used to work.

The values were stored in a cell like: 6, 7, 5, 8

 

but know they are stored like:

 

id   | people_id   | people_interests |

---------------------------------------------

1    | 44               | 2                        |

2    | 44               | 3                        |

 

How do i change this to show checked values from the new table structure:

<?php  
$query="select people_interests from People where people_id='{$_GET['id']}'";
$row=mysql_fetch_object(mysql_query($query));
$interests_array=split(",",$row->people_interests);
$qt=mysql_query("SELECT interest_no, interest FROM Interests");
$checked="";
while($interests=mysql_fetch_array($qt)){
if(in_array($interests['interest_no'],$interests_array)){$checked="checked";}
else{$checked="";}
echo "<label class=checkboxclm><input type=checkbox name=people_interests[] value='$interests[interest_no]' $checked> $interests[interest]</label>";
}
?>

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/287056-php-checked-checkbox-values/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.