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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating variable names from variables

Status
Not open for further replies.

jimoblak

Instructor
Oct 23, 2001
3,620
US
Is it possible to create a variable with another variable?

I would like to create a form element like this in PHP...

while ($Row = mysql_fetch_array ($Result)) {
print (&quot;<input type=\&quot;text\&quot; size=\&quot;4\&quot; name=\&quot;q$Row[Item]\&quot;>\n&quot;);
}

The requested input is for a quantity of items to order. A WHILE statement runs through the entire database of items to produce something like this in HTML on the form submission page...

<input type=&quot;text&quot; size=&quot;4&quot; name=&quot;qapples&quot;>
<input type=&quot;text&quot; size=&quot;4&quot; name=&quot;qpears&quot;>
<input type=&quot;text&quot; size=&quot;4&quot; name=&quot;qbananas&quot;>

The problem occurs when I want to handle the form-submitted data.

I ignorantly try the following code for handling the data on the form handler page...

while ($Row = mysql_fetch_array ($Result)) {
if ($q$Row[Item]) {
print (&quot;You want $q$Row[Item] of $Row[Item]<br>\n&quot;);
}}

This last code does not work, of course, and I find myself begging for the gift of wisdom. Is there a way to do this? How can '$q$Row[Item]' be interpreted as a single variable?
 
You could try ${&quot;q&quot; . $Row['Item']}. Though I am not sure it would work, but it is worth a shot. //Daniel
 
I got the following to work. Thanks Daniel

$value=${&quot;q$Row[Item]&quot;};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top