parsing concatenated strings?
Hi,
I am new to PHP and cant seem to find a way to parse a concatenated string and variable.
To explain:
I have a database to catalogue a composers works, one of the tables has a list of instruments which I then access to dynamically display on a wep page using checkboxes - if a particular instrument is used in the work then the checkbox is checked.
<?php
$resultInstrument = mysql_query("SELECT * FROM instrumentTbl ORDER BY sort_order");
if ($myrowInstrument = mysql_fetch_array($resultInstrument)) {
do {
echo $myrowInstrument['instrument'];
echo ": ";
?>
<input name="<?php echo $myrowInstrument['instrument']; ?>" type="checkbox" value="<?php echo $myrowInstrument['instrument']; ?>">
So far so good.
The problem I am having is when I want to insert the number of instruments used in the work.
<input name="<?php echo $myrowInstrument['instrument']; ?>number" type="text" size="3">
This snipet of code produces a dynamically created form where the user can enter the number of instruments.
Here is a part of the form created from the code above:
<input name="Flutenumber" type="text" size="3">
To process the information in this form I think I need to concatenate $instrument with the string 'number'. the only problem is that PHP reads this literally and the output is just $Flutenumber and not the number actually entered.
Here is the code I have at the moment
$resultInstrument_id = mysql_query("SELECT * FROM instrumentTbl ORDER BY sort_order");
while ($myrowInstrument_id = mysql_fetch_array($resultInstrument_id))
{
$instrument = $myrowInstrument_id['instrument'];
if (strlen ($$instrument !='0'))
{
//this works fine and gives a list of all the checked instruments
print $$instrument;
//this just outputs the literal interpretation
print "$${$instrument}number";
}
}
Any help would be greatly appreciated.
Thanks,
Paul.
|