Jump to content

implode from checkbox


Mutley

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

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.