tigomark Posted February 18, 2008 Share Posted February 18, 2008 Hello, I am having some problems using implode in my script. I am trying to take the array of a multi select and create a comma separated list for a query. When the form posts it works as expected but when I go to sort my different columns it tries to cut down the comma separated lest again until it reaches just one instance. if (isset($_REQUEST["datatypetarget"]) && is_array($_REQUEST["datatypetarget"]) && count($_REQUEST["datatypetarget"]) > 0) { $array = ($_REQUEST["datatypetarget"] ? $_REQUEST["datatypetarget"] : ""); $this->datatypetarget .= implode($array , ","); } else if (!is_array($_REQUEST["datatypetarget"])) { $this->datatypetarget = ($_REQUEST["datatypetarget"] ? $_REQUEST["datatypetarget"] : ""); } The link code $myopts = sprintf("startyear=%d&startmonth=%d&startday=%d&endyear=%d&endmonth=%d&endday=%d&showall=%d&datatypetarget=%s", $this->startdate->year, $this->startdate->month, $this->startdate->day, $this->enddate->year, $this->enddate->month, $this->enddate->day, $this->showall, $this->datatypetarget); When the form is posted I have an array of up to 5 values 1,2,3,4,5 However with each sort the implode is causing it to diminish 1,2,3,4 1,2,3 1,2 1 1 1 1 and so on. Will I need to add another type of checking to get this to work corectly? Quote Link to comment Share on other sites More sharing options...
Chris92 Posted February 18, 2008 Share Posted February 18, 2008 try, implode("," ,$array); Maybe there should be a number at the end like the explode function implode("," ,$array, -1); Quote Link to comment Share on other sites More sharing options...
tigomark Posted February 18, 2008 Author Share Posted February 18, 2008 Thanks for the idea. That didn't make any difference. Quote Link to comment Share on other sites More sharing options...
tigomark Posted February 18, 2008 Author Share Posted February 18, 2008 I've tried adding in a n explode for the sorts no change if (isset($_REQUEST["datatypetarget"]) && is_array($_REQUEST["datatypetarget"]) && count($_REQUEST["datatypetarget"]) > 0) { $array = ($_REQUEST["datatypetarget"] ? $_REQUEST["datatypetarget"] : ""); $this->datatypetarget .= implode($array , ","); echo"First<br/>"; } else if (!is_array($_REQUEST["datatypetarget"])) { $array = explode("," , $_REQUEST["datatypetarget"]); echo"Second<br/>"; $this->datatypetarget .= implode($array , ","); } Quote Link to comment Share on other sites More sharing options...
tigomark Posted February 18, 2008 Author Share Posted February 18, 2008 The problem was not in the code blocks but a count function that was not keeping proper track of the field count finished code if (isset($_REQUEST["datatypetarget"]) && is_array($_REQUEST["datatypetarget"]) && count($_REQUEST["datatypetarget"]) > 0) { $array = ($_REQUEST["datatypetarget"] ? $_REQUEST["datatypetarget"] : ""); $this->datatypetarget .= implode($array , ","); $this->formhandler = count($_REQUEST["datatypetarget"]); } else if (!is_array($_REQUEST["datatypetarget"])) { $array = explode("," , $_REQUEST["datatypetarget"]); $this->datatypetarget .= implode($array , ","); $this->formhandler = count($array); } Quote Link to comment 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.