Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/143923-implode-from-checkbox/
Share on other sites

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']);

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.