jesushax Posted March 24, 2009 Share Posted March 24, 2009 hi all im trying to get the fields T1 - T21 into an variable seperated by commas i did the below orginally, but then i get a load spare commas randomly placed for posts that are empty any ideas? Thanks $trades = $_POST["T1"].","; $trades .= $_POST["T2"].","; $trades .= $_POST["T3"].","; $trades .= $_POST["T4"].","; $trades .= $_POST["T5"].","; $trades .= $_POST["T6"].","; $trades .= $_POST["T7"].","; $trades .= $_POST["T8"].","; $trades .= $_POST["T9"].","; $trades .= $_POST["T10"].","; $trades .= $_POST["T11"].","; $trades .= $_POST["T12"].","; $trades .= $_POST["T13"].","; $trades .= $_POST["T14"].","; $trades .= $_POST["T15"].","; $trades .= $_POST["T16"].","; $trades .= $_POST["T17"].","; $trades .= $_POST["T18"].","; $trades .= $_POST["T19"].","; $trades .= $_POST["T20"].","; $trades .= $_POST["T21"]; Quote Link to comment https://forums.phpfreaks.com/topic/150897-solved-get-certain-fields-into-an-variable/ Share on other sites More sharing options...
kickstart Posted March 24, 2009 Share Posted March 24, 2009 Hi Something like this:- $trades = (($_POST["T1"]) ? $_POST["T1"]."," : ""); $trades .= (($_POST["T2"]) ? $_POST["T2"]."," : ""); $trades .= (($_POST["T3"]) ? $_POST["T3"]."," : ""); $trades .= (($_POST["T4"]) ? $_POST["T4"]."," : ""); $trades .= (($_POST["T5"]) ? $_POST["T5"]."," : ""); $trades .= (($_POST["T6"]) ? $_POST["T6"]."," : ""); $trades .= (($_POST["T7"]) ? $_POST["T7"]."," : ""); $trades .= (($_POST["T8"]) ? $_POST["T8"]."," : ""); $trades .= (($_POST["T9"]) ? $_POST["T9"]."," : ""); $trades .= (($_POST["T10"]) ? $_POST["T10"]."," : ""); $trades .= (($_POST["T11"]) ? $_POST["T11"]."," : ""); $trades .= (($_POST["T12"]) ? $_POST["T12"]."," : ""); $trades .= (($_POST["T13"]) ? $_POST["T13"]."," : ""); $trades .= (($_POST["T14"]) ? $_POST["T14"]."," : ""); $trades .= (($_POST["T15"]) ? $_POST["T15"]."," : ""); $trades .= (($_POST["T16"]) ? $_POST["T16"]."," : ""); $trades .= (($_POST["T17"]) ? $_POST["T17"]."," : ""); $trades .= (($_POST["T18"]) ? $_POST["T18"]."," : ""); $trades .= (($_POST["T19"]) ? $_POST["T19"]."," : ""); $trades .= (($_POST["T20"]) ? $_POST["T20"]."," : ""); $trades .= (($_POST["T21"]) ? $_POST["T21"] : ""); All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/150897-solved-get-certain-fields-into-an-variable/#findComment-792708 Share on other sites More sharing options...
crazyone Posted March 24, 2009 Share Posted March 24, 2009 If T1 to T21 is the only thing you have in your array then do the following: $trades = implode(',', $_POST); Else you could extract those values by walking the array and taking the values if they start with T. For example: $ExtractedResults = array(); function GetTFields(&$item1, $key){ global $ExtractedResults; if(substr($key, 0, 1) == 'T' && is_numeric(substr($key, 1)) && (int)(substr($key, 1)) >= 1 && (int)(substr($key, 1)) <= 21){ $ExtractedResults[$key] = $item1; } } array_walk($_POST, 'GetTFields'); $trades = implode(',', $ExtractedResults); Cheers Quote Link to comment https://forums.phpfreaks.com/topic/150897-solved-get-certain-fields-into-an-variable/#findComment-792710 Share on other sites More sharing options...
crazyone Posted March 24, 2009 Share Posted March 24, 2009 Sorry i didnt read the post correctly, but you could take my second advice and simply put another condition that checks if the value is set... Quote Link to comment https://forums.phpfreaks.com/topic/150897-solved-get-certain-fields-into-an-variable/#findComment-792711 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.