473,394 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

concatenate object variable name

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.
Oct 3 '05 #1
3 7153


Bosconian wrote:
I have form values stored in an object.
I suppose you stored them in separate variables. It may be handier to
use an array for that.

When calling a method, you can pass the array index as a parameter.

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.

Oct 3 '05 #2
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.
js*******@attglobal.net
==================
Oct 3 '05 #3
"Bosconian" <bo*******@planetx.com> wrote in message
news:P7********************@comcast.com...
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.


When concatenating objects in the above example simply

$node->specialty . $i

eval is not needed.
Oct 11 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Len Burman | last post by:
I have some code in a form which inputs a friends email address and when you submit it sends the message to the person at the address. I want to be able to email to the variable name and also a...
30
by: priya | last post by:
Hi How to concatenate two integer Values. Example Program : #include "Port.h" #include "BinaryConversion.h" # include "iostream.h"
2
by: SABmore | last post by:
I have a table that I populate with an array using ASP. As each row is created, the form object names are appended a numeric, such as: i = 1 <select name="select<%=i%>"> ... ... ... i = i+1...
3
by: tirrell payton | last post by:
Hello all, I have a question about the concatenation operator in C#. For example, I want to concatenate an integer variable to a control. I have an integer, i. I have checkboxes, checkbox0 -...
5
by: Generic Usenet Account | last post by:
I have been to recreate a problem that I am having with strings with the trivial code snippet given below. In the trivial code example, I am reading five lines from a data file, each line having...
1
by: Peter | last post by:
Hi, I know that it is possible to build up a variable name based on a string and another variable name i.e. $varnum=5; ${"varnumber_$varnum"} = 'This variable should be called varnumber_5'; ...
10
by: Aaron Hoffman | last post by:
Hello, I'm hoping someone might be able to offer some guidance to my problem. I have one query in MS Access which consists of 2 tables joined by a SEQUENCE_ID. By joining the two tables I am...
1
by: Tony Bansten | last post by:
Assume I want to concatenate a literal text value and a variable value for a function parameter then the following does NOT work: objWorkbook.SaveAs("D:\work\v1_" + Filename) The variable...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.