troubleshooting Question

Convert php array to comma seperated list

Avatar of peter-cooper
peter-cooper asked on
19 Comments2 Solutions152 ViewsLast Modified:
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


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


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

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

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

   $('#submit3').click(function () {
   $('#boxdest').append($('#boxdest2 > option').clone());

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;
Banshi lal dangi
Full Stack Developer

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

Join our community to see this answer!
Unlock 2 Answers and 19 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros