Counter syntax problem

This is a discussion on Counter syntax problem within the PHP Language forums, part of the PHP Programming Forums category; I am having a problem with php syntax. I am sending these values to a form called preview.php but ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2006
Garry Jones
 
Posts: n/a
Default Counter syntax problem

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.

$fornamn1
$eftnamn1
$fornamn2
$eftnamn2

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

<php
$po = 1;
?>

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

<?php
$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.

Ie

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

works.

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

<?= $fornamn.$po ?>

to actually call fornamn1

Any help greatly appreciated.

Garry Jones
Sweden



Reply With Quote
  #2 (permalink)  
Old 04-20-2006
milahu
 
Posts: n/a
Default 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
<?php=$_GET['array']['index']?>

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

Reply With Quote
  #3 (permalink)  
Old 04-21-2006
Jerry Stuckle
 
Posts: n/a
Default Re: Counter syntax problem

Garry Jones wrote:
> 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.
>
> $fornamn1
> $eftnamn1
> $fornamn2
> $eftnamn2
>
> On preview.php I want to use a counter in the names like this.
>
> <php
> $po = 1;
> ?>
>
> <?= $fornamn.$po ?>&nbsp;<?= $eftnamn.$po ?>
>
> <?php
> $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.
>
> Ie
>
> <?= $fornamn1 ?>&nbsp;<?= $eftnamn1 ?>
> <?= $fornamn2 ?>&nbsp;<?= $eftnamn2 ?>
>
> works.
>
> But I want to simplify the code. So how do I get
>
> <?= $fornamn.$po ?>
>
> to actually call fornamn1
>
> Any help greatly appreciated.
>
> Garry Jones
> Sweden
>
>
>


Garry,

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.
jstucklex@attglobal.net
==================
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:00 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0