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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.