FOR LOOP

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

miguelna
New php-forum User
New php-forum User
Posts: 15
Joined: Wed Sep 04, 2002 12:53 am

FOR LOOP

Postby miguelna » Tue Sep 17, 2002 7:21 am

wat's wrong with the following code? I want change the values at right of the x and y. $x1, $x2, $x3.... and $ponto1[2], $ponto2[2], $ponto3[2]...
I tried $x$i

Help!!!

Code: Select all

<? for ($i = 1; $i < 23; $i++) {
?>
<area shape="rect" coords="<? echo $x$i.",".$y$i.",".($x$i+10).",".($y$i+10) ?>" href="<? echo "$PHP_SELF?a_cor=1"; ?>" alt="<? echo $ponto$i[2] ?>">
<?
}
?>


Thanks
Miguel

elitecodex
New php-forum User
New php-forum User
Posts: 68
Joined: Tue Jul 09, 2002 8:45 am
Location: East Coast, USA
Contact:

Postby elitecodex » Tue Sep 17, 2002 8:52 am

Are you getting any errors? I do noticed that you missed some semi-colon's on the end of your echo statements. Try appending those and see what happens.

miguelna
New php-forum User
New php-forum User
Posts: 15
Joined: Wed Sep 04, 2002 12:53 am

Postby miguelna » Tue Sep 17, 2002 8:55 am

my code is:

Code: Select all

<? for ($i = 1; $i < 23; $i++) {
?>
<area shape="rect" coords="<? echo $x.$i.",".$y.$i.",".($x.$i+10).",".($y.$i+10) ?>" href="<? echo "$PHP_SELF?a_cor=1"; ?>" alt="<? echo $ponto.$i[2] ?>">
<?
}
?>

elitecodex
New php-forum User
New php-forum User
Posts: 68
Joined: Tue Jul 09, 2002 8:45 am
Location: East Coast, USA
Contact:

Postby elitecodex » Tue Sep 17, 2002 9:03 am

ok, so change it to this:

Code: Select all

<? for ($i = 1; $i < 23; $i++) {
?>
<area shape="rect" coords="<? echo $x.$i.",".$y.$i.",".($x.$i+10).",".($y.$i+10); ?>" href="<? echo "$PHP_SELF?a_cor=1"; ?>" alt="<? echo $ponto.$i[2]; ?>">
<?
}
?>


and if $ponto is an array, why are you accessing it like "$ponto.$i[2]" ? Im confused on what your trying to do.

miguelna
New php-forum User
New php-forum User
Posts: 15
Joined: Wed Sep 04, 2002 12:53 am

Postby miguelna » Tue Sep 17, 2002 9:19 am

I have some arrays $ponto1, $ponto2,… and I want print the field [2] of the array. My problem is concatenate $ponto with $i to generate the desired name for link to the array.

The same for x. I want a script to increase the value in the right of x, to $x1, $x2, $x3…

Jay

Postby Jay » Tue Sep 17, 2002 2:31 pm

Err, are you looking to use $x[$i] instead of $x$i ??


Return to “PHP coding => General”

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests