Page 1 of 1

Field Name+Variable question

Posted: Wed May 11, 2011 3:03 pm
by DedMousie
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.

Re: Field Name+Variable question

Posted: Wed May 11, 2011 3:11 pm
by Kurby
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.

Re: Field Name+Variable question

Posted: Wed May 11, 2011 3:35 pm
by flying_circus
DedMousie wrote: I've tried goofy stuff (?) like: $_POST["parf_+$myVAR"] but so far, nothing seems to work for me.
The + operator does not concatenate in PHP, the "." does. Try something like $_POST["parf_" . $myVAR]

Edit: Whoops, looks like Kurby beat me to it. :)

Re: Field Name+Variable question

Posted: Wed May 11, 2011 6:08 pm
by DedMousie
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 ...

Re: Field Name+Variable question

Posted: Wed May 11, 2011 11:03 pm
by flying_circus
[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