Re: concatenate object variable name
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: concatenate object variable name

From: Jerry Stuckle <jstucklex@attglobal.net>
Date: Mon Oct 03 2005 - 17:04:34 CEST

Bosconian wrote:
> I have form values stored in an object.
>
> I have a set of numbered form fields:
>
> specialty1
> specialty2
> specialty3
>
> I need to loop through these, check for content and process accordingly. I
> can't figure out how to correctly concatenate the number to the end of the
> field name. For example:
>
> for ($i = 1; $i <= 3; $i++) {
> if (eval("$node->specialty" . $i)) {
> //do something
> }
> }
> I know eval is slow, but what other options are there?
>
> Thanks.
>
>

As Willem said - use an array. For instance:
   <form action="..." method="post">
     <b>Specialty 1</b><input type="text" name="specialty[]"><br>
     <b>Specialty 2</b><input type="text" name="specialty[]"><br>
     <b>Specialty 3</b><input type="text" name="specialty[]"><br>
     (other stuff)
   </form>

In your target's code,

   $specialty=$_POST['specialty'];

The three (if they are filled in) will be in $specialty[0],
$specialty[1] and $specialty[2].

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Received on Tue Oct 18 02:30:56 2005