Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to increment the name of a $scalar

Status
Not open for further replies.

calabama

Programmer
Feb 19, 2001
180
US
Want to increment the name of a $scalar followed by $x.

Example:$scalar1,$scalar2,$scalar3,etc.

#######################################

for ($x=0; $x <= $elements; $x++) {
$scalar$x='<select size='1' name='M$x'>$fname<OPTION>GUEST</OPTION><option selected>Select a member</option></select>'
}
}


Thanks In the begining
Let us first assume that there was nothing to begin with.
 
$Scalar[$x] gives no error but data back.
--------------------------------------------
I will try to be more clear.

I am building pull down menus on the fly. Because the number of elements change.

This result of the loop is basicly ($variable = pull down menu)
The variable need to be uniquely identified.
example:

$fname_menu1
$fname_menu2
$fname_menu3
$fname_menu4


Any $scalar name or prefix would be fine as long as it preceeds a unique number, preferably sequential.

$x is the counter value.
################# LOOP ##########################
for ($x=0; $x <= $elements; $x++) {

$scalar$x='<select size='1' name='M$x'>$fname

<OPTION>GUEST</OPTION>
<option selected>Select a member</option>
</select>'
}
}
#################################################

In the begining
Let us first assume that there was nothing to begin with.
 
Try this. It's very similar to what you have already. I used this for an upload script to be used to submit articles for our internal website. Please let me know if this isn't what you're looking for.

for($c=1; $c<=$elements; $c++)
{
print <<SECONDPART;
<TR>
<TD><INPUT TYPE='file' NAME='upload$c' ></TD>
<TD><SPAN CLASS='audience'><INPUT TYPE='CHECKBOX' NAME='spcheck$c' CHECKED>&nbsp;Service&nbsp;Partner<BR>
<INPUT TYPE='CHECKBOX' NAME='ppcheck$c' CHECKED>&nbsp;Producer&nbsp;Partner<BR>
<INPUT TYPE='CHECKBOX' NAME='lpcheck$c'>&nbsp;Limited&nbsp;Partner<BR>
<INPUT TYPE='CHECKBOX' NAME='trcheck$c'>&nbsp;Terminated&nbsp;PPA<BR>
<INPUT TYPE='CHECKBOX' NAME='tpcheck$c'>&nbsp;TPA</SPAN></TD>
<TD><INPUT TYPE='text' NAME='title$c' SIZE='25'><BR>
<TEXTAREA NAME='description$c' COLS='25' ROWS='6' WRAP='VIRTUAL' maxlength='255'></TEXTAREA></TD>
<TD><SELECT NAME='category$c'>
<OPTION VALUE=''>**Choose a Category**</OPTION>
<OPTION VALUE='1'>Table of Contents</OPTION>
<OPTION VALUE='2'>Products/Services</OPTION>
<OPTION VALUE='3'>Contracts/Proposals</OPTION>
<OPTION VALUE='4'>Administration/Processing</OPTION>
<OPTION VALUE='5'>Systems</OPTION>
<OPTION VALUE='6'>Compliance</OPTION>
</SELECT></TD>
</TR>
SECONDPART
}
 
Thanks Rieekan,

This works fine when printing within the initial cgi

I guess my problem is how do I concantenate a fixed $scalar with a changing $scalar using the same counting variable.

$scalar.$c In the begining
Let us first assume that there was nothing to begin with.
 
Oh, sorry about that. If you pass $elements as a hidden variable upon the submission of the form (using <input type='hidden'> tags) with the various dropdowns, just do the following to process the various scalars simply and easily by using the following:

$elements = param('Your_Hidden_Variable_name_here');
for ($c=1; $c<=$elements; $c++)
{
# Process your information using the variable $scalar$c
}
 
The way to interpolate a variable into a variable name is like this:
Code:
${scalar$x} = &quot;whatever&quot;;
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
dragon,

Thanks so much. This makes a great deal of sense. When I use the loop below in the script the scalars:$fname_menu1, $fname_menu2 etc. keep coming up empty.

Any ideas?

Cal

############ loop ###################
for ($x=0; $x <= $elements; $x++) {
${fname_menu$x} = &quot;<select size='1' name='M$x'>$fname<OPTION>GUEST</OPTION><option selected>Select a member</option></select>&quot;
}
############################################### In the begining
Let us first assume that there was nothing to begin with.
 
It looks OK to me. The only thing I can think of that might help is to do this:
Code:
${&quot;fname_menu&quot;.$x} = ...
I'm not sure that will help, but it probably couldn't hurt.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top