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"]; 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 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 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... 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
Archived
This topic is now archived and is closed to further replies.