Jump to content

Problems with implode


tigomark

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/91712-problems-with-implode/
Share on other sites

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 , ",");
}

Link to comment
https://forums.phpfreaks.com/topic/91712-problems-with-implode/#findComment-469869
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/91712-problems-with-implode/#findComment-469899
Share on other sites

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.