Field Name+Variable question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DedMousie
Forum Newbie
Posts: 12
Joined: Sat Feb 12, 2011 7:21 pm

Field Name+Variable question

Post 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.
Kurby
Forum Commoner
Posts: 63
Joined: Tue Feb 23, 2010 10:51 am

Re: Field Name+Variable question

Post 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.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Field Name+Variable question

Post 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. :)
DedMousie
Forum Newbie
Posts: 12
Joined: Sat Feb 12, 2011 7:21 pm

Re: Field Name+Variable question

Post 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 ...
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Field Name+Variable question

Post 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
Post Reply