Mutley Posted February 5, 2009 Share Posted February 5, 2009 Hi guys, I'm trying to do an implode from a load of checkboxes, basically I want to create a string that I can explode to get all the download ids. Here is how the checkboxes are created: <?php $c=1; $sql="SELECT `id`, `title`, `filetype`, `filesize` FROM `downloads` ORDER BY `title`"; $res=mysql_query($sql); if(mysql_num_rows($res)!=0) { while(list($id, $title, $filetype, $filesize) = mysql_fetch_row($res)){ ?> <input type="checkbox" value="1" name="<?=$id?>" /><b><?=$title?></b>(<?=$filetype?>/<?=$filesize/1000?>kb) <? if($c==3){ echo "<br />"; $c=1; } $c++; } } ?> Then to insert into database, I figured creating a variable for each POST from the checkboxes, checking if they are checked, then goto insert... just not sure if this is right? <?php $sql="SELECT id FROM downloads"; $res=mysql_query($sql); if(mysql_num_rows($res)!=0) { while(list($id) = mysql_fetch_row($res)){ if($_POST["$id"]==1){ $dl.$id=$_POST["$id"]; } } ?> But then how do I implode it? Thanks, Nick. Quote Link to comment https://forums.phpfreaks.com/topic/143923-implode-from-checkbox/ Share on other sites More sharing options...
aschk Posted February 5, 2009 Share Posted February 5, 2009 You want to name your input box something else. Try "options[$id]" instead. Then when you POST you'll get an array of chosen options, i.e. $_POST['options'] is an array containing all the values from your chosen checkboxes. Then you can just do implode(",", $_POST['options']); Quote Link to comment https://forums.phpfreaks.com/topic/143923-implode-from-checkbox/#findComment-755224 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.