Jump to content

Quick variable question...


kalevra

Recommended Posts

I have a script that makes a html form like this:

$i=1;

while ($i<=5){

echo "<input type="text" name="name$i"><br />";

}

 

Now the script getting the form looks something like this:

while($i<=5){

echo "<tr><td>Name:</td><td> $name$i </td></tr>";

}

 

The problem comes from the "$name$i" which doesn't behave like I would like it to.

I would like the source echo'ed from the script to be something like:

 

<tr><td>Name:</td><td> $name1 </td></tr>

<tr><td>Name:</td><td> $name2 </td></tr>

<tr><td>Name:</td><td> $name3 </td></tr>

<tr><td>Name:</td><td> $name4 </td></tr>

<tr><td>Name:</td><td> $name5 </td></tr>

 

And actually get all the values from the different input fields echo'ed.

 

 

Link to comment
https://forums.phpfreaks.com/topic/123294-quick-variable-question/
Share on other sites

The problem is when the form is sent to the script,

I would like to get the values of all the $name ($name1, $name2, $name3,...) in a loop, but doing it using:

 

$name$i and incrementing $i doesn't work. I assume that is because when the script runs it gives

the value of $name (which is nothing) and then the value of $i (which is 1,2,3,4,5) instead of giving the value of $name1,$name2... etc.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.