Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Convert php array to comma seperated list

Avatar of peter-cooper
peter-cooper asked on
PHP
19 Comments1 Solution152 ViewsLast Modified:
Hi
I have an array that I need to convert to comma seperated for inclusion in mysql. I have posted my code and would appreciate any help or guidance. Thanks

output:

[boxdest] => Array
        (
            [0] => WD1
            [1] => WD10
            [2] => WD11
        )

php

<?php
	        $conn = mysql_connect("localhost","root","");
		mysql_select_db("sample",$conn); 
		$result = mysql_query("SELECT * FROM boxes where department = '{$_GET['dept']}' ORDER BY custref ASC");
?>
								
		<select name="boxdest[]" id="boxdest" size="7" multiple="multiple">

<?php
		$i=0;
		while($row = mysql_fetch_array($result)) {
?>
		<option value="<?php echo $row["custref"];?>"><?php echo $row["custref"];?></option>
<?php
		$i++;
		}
?>
		</select>

<input type="button" id="submit2" name="submit2" value=">" />
<input type="button" id="submit3" name="submit3" value="<" />
<select name="boxdest2[]" id="boxdest2" size="7"  multiple="multiple"></select>

<script type="text/javascript">
	
  $('#submit2').click(function () {
  var selected = $('#boxdest > option:selected');
  $('#boxdest2').append(selected.clone());
  selected.hide();
});

   $('#submit3').click(function () {
   $('#boxdest').append($('#boxdest2 > option').clone());
   $('#boxdest2').empty();
});
</script>

results page
This is what I have tried in results page

if (isset($_POST['boxdest'])) 
	{
 
        if (!empty($_POST['boxdest'])) 
		{
 								
                $destroydata = split(',', $_POST['boxdest'][0]);
 		$result = array();
                
                                                                
                foreach ($destroydata as $val4)
                {
			if ( $val4 != "" )
                        {
                                
                                  $boxdest[] = $val4;
				  $result[] = $boxdest;
				    
                        }
              }
      }
ASKER CERTIFIED SOLUTION
Avatar of Banshi lal dangi
Banshi lal dangiFlag of India imageFull Stack Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 19 Comments.
See Answers