CakePhp: how to set a select using $this->Form->input with values from 1 to 100? - forms

I am using Cakephp and I would like to learn how to set a select with values from 1 to 100?
Please notice I prefer to use $this->Form->input if possible.

TLDR:
echo $this->Form->input('whatever', array(
'type'=>'select',
'options'=>array_combine(range(1,100), range(1,100))
));
Explanation:
PHP's range creates an array of numbers (or letters), which is what you want for your options. But if you use range by itself, it creates:
array(1,2,3,4...
This would give you a dropdown of numbers, but the values will start with zero regardless of the displayed number - in this case, you'd end up with array(0=>1, 1=>2 ...
When you really want this:
array(1=>1, 2=>2, 3=>3 ...
By using array_combine just makes it so the first option has the same value as the displayed number.
(obviously you can write this in 1 line - I just broke it up for ease of reading)

Related

How do I prevent users to use thousands separator in FileMaker Pro?

In FileMaker Pro, when using number field, the user can choose to use a thousand separator or not. For example, if I have a database with a field for the price of an item, the user can either enter 1,000 or 1000.
I am using my database to generate an XML file that needs to be uploaded. The thing is, that my XML scheme dictates that only a value of 1000 is allowed and not 1,000. Therefore, I want to either automatically remove the comma, or (my preference in this case) alert the user when trying to enter a value with a thousand separator.
What I tried is the following.
For the field, I am setting Validation options. For example:
Require Strict data type: Numeric Only
Validated by calculation: Position ( Self ; ","; 1 ; 1 ) = 0
Validated by calculation: Self = Substitue ( Self, ",", "")
Auto-enter calculation: Filter( Self ; "0123456789." )
Unfortunately, none of these work. As the field is defined as a number (and I want to keep it like this, as I am also performing calculations based on this number), the Position function and the Substitute function apparently ignore the thousand separator!
EDIT:
Note that I am generating my XML by concatenating a string, for example:
"<Products><Product><Name>" & Name & "</Name><Price>" & Price & "</Price></Product></Product>"
The reason is that what I am exporting is dependent on the values in my database. Therefore, I am not using the [File][Export records...] function.
Auto-enter calculation will work, but you need to uncheck the box "Do not replace existing value of field" (which is checked by default).
I'd suggest using the calculation GetAsNumber(self) as the auto-enter calc. If it should only contain integers, wrap that in a call to Int()
I am using my database to generate an XML file that needs to be uploaded. The thing is, that my XML scheme dictates that only a value of 1000 is allowed and not 1,000.
If this is only a problem when you export, why not handle it when exporting?
If you are exporting as XML using XSLT, you can add an instruction to
your stylesheet to remove the comma from all number fields;
Alternatively, you can export from a layout where the field is
formatted to display without the comma and select the Apply current's layout data formatting to exported data option when
exporting.
Added:
Perhaps I should have clarified. I am not using the export function to generate the XML as there is some logic involved in how the XML should be formatted (dependent on the data that I want to export). What I do instead is that I make a string where I combine XML-tags and actual values from the database.
IMHO, you're making a mistake by not taking advantage of the built-in XML/XSLT export option. Any imaginable logic can be implemented this way, without burdening your solution with the fragile task of creating a valid XML.
In any case, if you're using the field in a calculation, you can replace all references to it with:
GetAsNumber (YourField )
to get an unformatted, numeric-only, value.
Your question puzzles me. As far as I know, FileMaker does not store the thousands separator, but rather offers it only as a display option.
That's also why those functions can't find it.
Are you sure you are exporting the raw data and not a "formatted as layout" variant?

How to reach the end of a chain of cells

I have a file with two sheets:
sheet_A
A B
1 Mr. Joe USD
sheet_B
A B
1 =sheet_A.A1 ???
sheet_B.B1 shall show the value USD. I know i could get it easily with =sheet_A.B1 but I do not want that.
If I enter into sheet_B.B1 =ADDRESS(ROW();COLUMN()-1) I get the output $C$1 and with =INDIRECT(ADDRESS(ROW();COLUMN()-1)) Mr. Joe.
How can I "navigate" through a chain sheet_B.B1 - sheet_B.A1 - sheet_A.A1 - sheet_A.B1?
Edit 1
Maybe I need something like this
=OFFSET(FORMULA(ADDRESS(ROW();COLUMN()-1);0;1)#
sheet_B.B2 shall show the content of sheet_A.B2 in relation of the value in sheet_B.A1
Here are two possibilities. Either formula produces USD in sheet_B.B1.
=INDIRECT(ADDRESS(ROW();COLUMN();;;"sheet_A"))
=VLOOKUP(A1;$sheet_A.A1:B1;2)
Documentation: ADDRESS, VLOOKUP.
EDIT:
One more idea: The following produces the string "=sheet_A.A1", which could be parsed for the sheet name and cell address. Perhaps you would like to use it to refer to sheet_A.B1.
=FORMULA(INDIRECT(ADDRESS(ROW();COLUMN()-1)))
However, as I commented, there is probably an easier way for what you are trying to accomplish.
Documentation: FORMULA.
EDIT 2:
Here is the formula you requested. It uses REPLACE to remove = at the beginning of the string.
=OFFSET(INDIRECT(REPLACE(FORMULA(INDIRECT(ADDRESS(ROW();COLUMN()-1)));1;1;""));0;1)

Parameter field with multiple values not working

Setup a Parameter field with multiple values to be used in a SQL query command and it does not work when more than one value is selected, but works fine with one value selected. And yes, the "Allow multiple values" flag is set to True under Options.
I am trying to go from this:
EMPBNFIT.BENEFITPLAN in ('CONSUMER CHOICE','HMO', 'HS HMO','HS NETWORK CHOICE','HS PPO BASIC NH RPN','HS PPO PLUS NH RPN','MFS CONSUMER CHOICE','NETWORK CHOICE','PPO BASIC NH RPN','PPO PLUS NH RPN','WAIVE MEDICAL')
to this:
WHERE EMPBNFIT.BENEFITPLAN in ('{?MyPlans}')
What a coincidence; had the same problem this morning. I was able to make a workaround in Crystal by converting the array of multiple parameters into a single string, then replacing the IN section with an INSTR comparison.
Make a formula called ParamFix with this logic:
REPLACE(JOIN({?MyPlans}, ","), "&", "; ")
In my case, the different values were separated by an &, but you can replace that based on what comes back from the tables. Then replace the IN comparison with:
INSTR({#ParamFix}, EMPBNFIT.BENEFITPLAN) > 0

Stata: append two datasets, retain value labels

I'm using Stata14 and I'm trying to append two survey datasets that have ~200 variables with same names but different values and value labels. I would like to do the appending so that value labels are retained from the dataset 'on disk'.
Here is an example describing my problem:
Variable in dataset 1 (master):
value - label
1 - yes
2 - no
Same variable in dataset 2 (appended to master):
value - label
1 - yes absolutely
2 - no definitely not
3 - maybe
4 - don't know
Result with append using "dataset 2.dta"
value - label
1 - yes
2 - no
3 - 3
4 - 4
Desired result:
value - label
1 - yes
2 - no
3 - maybe
4 - don't know
Is there any way to do this directly using append? If not, any suggestions on doing the task efficiently are most welcome.
You want to make value labels consistent, which is sensible, fine and easy to do.
When you have appended all the datasets, you then overwrite any value label assignment with a quick
label define whatever 1 yes 2 no 3 maybe 4 "don't know"
label val myvar whatever
with a , modify on the first if a set of value labels with that name already exists.
It's a task to do late. It doesn't need to be fixed before or during the append, and it can most easily be done at that point.
Naturally, this is tedious for several variables, but it's not difficult to understand. Furthermore, even if append were able to take instructions on which labels to use, you would still have to spell that out. In your example, the value labels you want are not actually in use in any of the datasets. So, there will be some inevitable pain. There is a mess to sort out and what the fix is can't be fully automated because it depends on your ideas of what labels are best.
in short, the answer is
NOPE
so you have to be smart. Try to use this trick http://www.stata.com/support/faqs/data-management/keeping-same-variable-with-collapse/ where you get a local copy of the labels that you will be attaching to the full dataset afterwards.

How to add operator signs '+,-,/,*,mod' etc to a label for making a calculator?

I have made a calculator for simple operations but I cant figure out how should I add the operator signs next to the numerals that I am entering.
I created 2 functions 1 on the number being entered
-(IBAction)buttonDigitPressed:(id)sender
and another for the operation
-(IBAction)buttonOperationPressed:(id)sender.
calculatorScreen.text = [NSString stringWithFormat:#"%.2f",result];
This is for the result to be shown on the label calculatorScreen.
The result i would like would be something like "1+2*3/4" on the calculatorScreen.
Sorry if I misunderstand your question, but what you want is to display on your calculator app the full equation that you've input thus far (e.g. 63+42-62).
Like any other calculator, you should have 2 label, one for your current input, and one to show all that you've entered.(I'm guessing you need the latter)
With the second label up, you can add in the append function into your digitpressed, enter/= function, operation function. If you want to tweak it such 16+23-32 will show up as
1) 16+23
2) 39-32
3) 39-32=7
then you'll have to add in your own specific code. otherwise the label will input as 16+23-32 = 7
You can just append the character to whatever is already on calculatorScreen. Or you can save the current input in an instance variable and display where appropriate.
This is just a guideline, since I don't know the behavior of your calculator in case of this input: 1 + 2 * 3 (simple calculator will return 9, scientific will return 7).