Jump to content

Getting data from a multi select field


tigomark

Recommended Posts

Hello,

 

I am having a problem parsing the data from a multi-select field

 

$html = "<select name=\"datatypetarget[]\" size=\"5\" multiple>\n";

 

The following is my parsing code to create a comma separated field I can put into a database call

 

$this->assettarget = ($_REQUEST["assettarget"] ? $_REQUEST["assettarget"] : "NULL::INTEGER");
//data target handler
    $this->datatypetarget1 = ($_REQUEST["datatypetarget1"] ? $_REQUEST["datatypetarget1"] : "''");
    $this->datatypetarget2 = ($_REQUEST["datatypetarget2"] ? $_REQUEST["datatypetarget2"] : "");
    $this->datatypetarget3 = ($_REQUEST["datatypetarget3"] ? $_REQUEST["datatypetarget3"] : "");
    $this->datatypetarget4 = ($_REQUEST["datatypetarget4"] ? $_REQUEST["datatypetarget4"] : "");
    $this->datatypetarget5 = ($_REQUEST["datatypetarget5"] ? $_REQUEST["datatypetarget5"] : "");
    var_dump($this->datatypetarget1);
    var_dump($this->datatypetarget2);
    var_dump($this->datatypetarget3);
    var_dump($this->datatypetarget4);
    var_dump($this->datatypetarget5);
    if (isset($_REQUEST["datatypetarget"]) && is_array($_REQUEST["datatypetarget"]) && count($_REQUEST["datatypetarget"]) > 0) {
    
foreach ($_REQUEST["datatypetarget"] as $data_type) {
if ($data_type != "") {
$this->datatypetarget .= "," . $data_type   ;
}else{
$this->datatypetarget = "";
break;
}
}
} else if (!is_array($_REQUEST["datatypetarget"])) {

$this->datatypetarget = $_REQUEST["datatypetarget"];
$this->data->datatypetarget = $this->datatypetarget;
}


 

 

Currently from the var_dumps I get

 

string(2) "''" string(0) "" string(0) "" string(0) "" string(0) ""

 

so I am missing some values.

Link to comment
Share on other sites

This code is pretty much meaningless unless you have input fields in your form called datatypetarget1, datatypetarget2, etc

//data target handler
    $this->datatypetarget1 = ($_REQUEST["datatypetarget1"] ? $_REQUEST["datatypetarget1"] : "''");
    $this->datatypetarget2 = ($_REQUEST["datatypetarget2"] ? $_REQUEST["datatypetarget2"] : "");
    $this->datatypetarget3 = ($_REQUEST["datatypetarget3"] ? $_REQUEST["datatypetarget3"] : "");
    $this->datatypetarget4 = ($_REQUEST["datatypetarget4"] ? $_REQUEST["datatypetarget4"] : "");
    $this->datatypetarget5 = ($_REQUEST["datatypetarget5"] ? $_REQUEST["datatypetarget5"] : "");
    var_dump($this->datatypetarget1);
    var_dump($this->datatypetarget2);
    var_dump($this->datatypetarget3);
    var_dump($this->datatypetarget4);
    var_dump($this->datatypetarget5);

 

this code looks good, just do a var_dump($this->datatypetarget); at the end

    if (isset($_REQUEST["datatypetarget"]) && is_array($_REQUEST["datatypetarget"]) && count($_REQUEST["datatypetarget"]) > 0) {
    
foreach ($_REQUEST["datatypetarget"] as $data_type) {
if ($data_type != "") {
$this->datatypetarget .= "," . $data_type   ;
}else{
$this->datatypetarget = "";
break;
}
}
} else if (!is_array($_REQUEST["datatypetarget"])) {

$this->datatypetarget = $_REQUEST["datatypetarget"];
$this->data->datatypetarget = $this->datatypetarget;
}

Link to comment
Share on other sites

I should have tried to explain is that I am trying to parse it 2 different ways to see where I was getting a result and that the separating of the info at least gave me the ''. I know it's not correct but trying to handle the information as an array

 

if (isset($_REQUEST["datatypetarget"]) && is_array($_REQUEST["datatypetarget"]) && count($_REQUEST["datatypetarget"]) > 0) {
    
foreach ($_REQUEST["datatypetarget"] as $data_type) {
if ($data_type != "") {
$this->datatypetarget .= "," . $data_type   ;
}else{
$this->datatypetarget = "";
break;
}
}
} else if (!is_array($_REQUEST["datatypetarget"])) {

$this->datatypetarget = ($_REQUEST["datatypetarget"] ? $_REQUEST["datatypetarget"] : "''");

}
var_dump($this->datatypetarget);

Bombs out

Link to comment
Share on other sites

The output is as follows

 

{ ["action"]=> string(8) "showopen" ["operation"]=> string(0) ""  ["datatypetarget"]=> array(2) { [0]=> string(1) "6" [1]=> string(1) "7" } ["assettarget"]=> string(1) "0" ["cfgtype"]=> string(2) "-1" ["startyear"]=> string(4) "2008" ["startmonth"]=> string(1) "2" ["startday"]=> string(2) "13" ["endyear"]=> string(4) "2008" ["endmonth"]=> string(1) "2" ["endday"]=> string(2) "14" ["goaction"]=> string(8) " Wait..." ["showunverified"]=> string(1) "0" }

 

string(0) "" string(0) "" string(0) "" string(0) ""

 

SQL: SELECT * from get_my_data_report(0, 0, 0, '2008-2-13'::timestamptz, '2008-2-14 23:59:59'::timestamptz, '' , -1, 0, 100)

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.