tigomark Posted February 14, 2008 Share Posted February 14, 2008 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. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 14, 2008 Share Posted February 14, 2008 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; } Quote Link to comment Share on other sites More sharing options...
tigomark Posted February 14, 2008 Author Share Posted February 14, 2008 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 Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 14, 2008 Share Posted February 14, 2008 At the beginning of the script, put: print_r($_REQUEST);exit; and post what the output is...just so we see if data is getting passed properly, and what it looks like... Quote Link to comment Share on other sites More sharing options...
tigomark Posted February 14, 2008 Author Share Posted February 14, 2008 The output is as follows { ["action"]=> string( "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( " 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) Quote Link to comment Share on other sites More sharing options...
tigomark Posted February 14, 2008 Author Share Posted February 14, 2008 I figured it out. I was still trying to parse those uneeded values. It works now. thanks for the help 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.