trassalg Posted August 4, 2007 Share Posted August 4, 2007 I have the following code and can't seem to get either the checkboxes to show their individual label nor retrieve their respective value from the database. Any ideas what I can do to fix this? <?php function checkbox($name,$label,$value_yn,$input='',$category_array='') { $chk = ''; $attr = $category_array; if(is_array($category_array)) { $attr = ''; foreach($category_array as $key=>$aValue) { $attr .= " $key=\"$aValue\""; } } if($value_yn == trim($input)) { $chk = ' checked="checked"'; } $tag = "<label><input type=\"checkbox\" name=\"value[$i]\" value=\"$value_yn\"".$attr.$chk." />$label</label>\n"; echo $tag; } ?> <?php $category_data = array( 1 => '<strong>1. ALIMENTOS</strong>', ... 1112 => '11.12 - Teorías<br>' ); ?> <?php include("includes/misc.inc"); include("includes/connection.inc"); $result = mysql_query("SELECT categories FROM articleTable WHERE articleIDNumber=$articleIDNumber"); while ($row = mysql_fetch_array($result)) { $row = explode(",", $category_data); } $category_array = array($category_data); echo "<table>\n <tr>\n <td>\n"; for ($i = 0; $i < count($category_data); $i++){ checkbox(); } ?> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/63255-retrieving-checkbox-values-from-database/ Share on other sites More sharing options...
marcus Posted August 4, 2007 Share Posted August 4, 2007 <input type="checkbox" name="list[]" value="$i"> The [] in list will tell the script [when passed] that, that variable is an array. $list = $_POST['list']; foreach($list AS $id){ $sql = "DO THIS TO THIS TABLE WHERE `id`=$id"; $res = mysql_query($sql) or die(mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/63255-retrieving-checkbox-values-from-database/#findComment-315310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.