Jump to content

[SOLVED] get certain fields into an variable


jesushax

Recommended Posts

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

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

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