Forum Moderators: coopster

Message Too Old, No Replies

Maths in echo?

         

wonderboy

10:17 pm on May 3, 2004 (gmt 0)

10+ Year Member



echo "<a href=\"content.php?categ=$categ&lower=[j]*5\">$id[j]</a>";

The echo above is in a while loop, what is the best way of getting the lower variable in the link to be equal to 5 times the value of j (the number that increments by 1 each time the while loop runs through).
Obviously [j]*5 will not work, so just wondering what will?

Thanks,
W.

isitreal

11:25 pm on May 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



echo "<a href=\"content.php?categ=$categ&lower=" . $j*5 . "\">$id[$j]</a>";

I assume you forgot the $ in front of the $j counter variable.

It's more efficient, by the way, to put all the stuff in the while loop into a variable then echo the variable after the loop is done.
pseudocode:

while loop condition
$temp = "<a href=\"content.php?categ=$categ&lower=" . $j*5 . "\">$id[$j]</a>";
$j++;
end loop

echo $temp;

wonderboy

11:06 am on May 4, 2004 (gmt 0)

10+ Year Member



lower=" . $j*5 . "\">$id[j]</a>";

that works, don't know why the dollar in front of the j made it not work.

Thanks!

W.