Sorry - sorta PHP noob.
Easy to do in Coldfusion. Haven't figured out in PHP yet.
I've a number of database field names:
parf_50
parf_100
parf_150
Let's assume "myVAR" equals 150. In Coldfusion I can call that specific field by doing:
fieldVALUE = #Form["parf_#myVAR#"]#
or by using "evaluate" (best practice is to avoid "evaluate" though...)
fieldVALUE = Evaluate("form.parf_[#myVAR#]")
What's the best way to do this in PHP?
I've tried goofy stuff (?) like: $_POST["parf_+$myVAR"] but so far, nothing seems to work for me.
TIA.
Field Name+Variable question
Moderator: General Moderators
Re: Field Name+Variable question
Are you just trying to build a query?
Are you looking for a certain index in an already populated array? Then $array["parf_$myvar"] should work. You had a + in there, no need for it.
Are you looking for a certain index in an already populated array? Then $array["parf_$myvar"] should work. You had a + in there, no need for it.
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: Field Name+Variable question
The + operator does not concatenate in PHP, the "." does. Try something like $_POST["parf_" . $myVAR]DedMousie wrote: I've tried goofy stuff (?) like: $_POST["parf_+$myVAR"] but so far, nothing seems to work for me.
Edit: Whoops, looks like Kurby beat me to it.
Re: Field Name+Variable question
Hmm ....
Ok, I'm trying to output the specific field result for my query:
$thisRATE[parf_250];
That works. No problem. But, the "250" part is a form variable: $_post[myVAR]
So, something like (but doesn't work): $thisRATE[parf_.$_post[myVAR]];
-------------------------------------------------------------------------------------------
Got it - finally:
$limit = $_POST['sum_limit'];
$theANSWER = $thisRATE[parf_.$limit];
-------------------------------------------------------------------------------------------
Still wrapping my head around some of the Coldfusion/PHP differences...
Yea - need somebody to point me to a good tutorial on PHP concatenation ...
Ok, I'm trying to output the specific field result for my query:
$thisRATE[parf_250];
That works. No problem. But, the "250" part is a form variable: $_post[myVAR]
So, something like (but doesn't work): $thisRATE[parf_.$_post[myVAR]];
-------------------------------------------------------------------------------------------
Got it - finally:
$limit = $_POST['sum_limit'];
$theANSWER = $thisRATE[parf_.$limit];
-------------------------------------------------------------------------------------------
Still wrapping my head around some of the Coldfusion/PHP differences...
Yea - need somebody to point me to a good tutorial on PHP concatenation ...
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: Field Name+Variable question
[quote="DedMousie"Yea - need somebody to point me to a good tutorial on PHP concatenation ...[/quote]
Sure
http://www.php.net/manual/en/language.o ... string.php
Sure
http://www.php.net/manual/en/language.o ... string.php