Counter syntax problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am having a problem with php syntax.

I am sending these values to a form called preview.php but I can not get the  
syntax working properly.


On preview.php I want to use a counter in the names like this.

$po = 1;

<?= $fornamn.$po ?>&nbsp;<?= $eftnamn.$po ?>

$po = $po + 1;

<?= $fornamn.$po ?>&nbsp<?= $eftnamn.$po ?>

I know the values are being sent to preview.php correctly because if I  
substitute $po for real numbers everything is displayed correctly.


<?= $fornamn1 ?>&nbsp;<?= $eftnamn1 ?>
<?= $fornamn2 ?>&nbsp;<?= $eftnamn2 ?>


But I want to simplify the code. So how do I get

<?= $fornamn.$po ?>

to actually call fornamn1

Any help greatly appreciated.

Garry Jones

Re: Counter syntax problem

First of all, relying on register_globals=on is just soo bad; Please
use $_GET['varnam'] resp. $_POST['varnam'] for accessing script
parameters instead.

Concerning your problem: You can pass arrays via the GET method by
using array[index] as varname. Use array[] for auto increment of the
index. To print a value, use

PS: Use $op++ instead of $po = $po + 1 :)

Re: Counter syntax problem

Garry Jones wrote:
Quoted text here. Click to load it


First of all, $formname isn't defined.  It should be 'formname'.  Second, use  
the increment (++) operator, i.e. (not checked for syntax)

<?$po = 0; ?>

<?= "formnamn[$po]"; ?>&nbsp;<?="eftnam$po++";?>

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline