Jump to content

php checked checkbox values


Go to solution Solved by Ch0cu3r,

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

  • Solution

Change

$row=mysql_fetch_object(mysql_query($query));
$interests_array=split(",",$row->people_interests);

to

$people_result = mysql_query($query);
$interest_array = array();
while($row = mysql_fetch_row($people_result )) {
    $interests_array[] = $row[0];
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.