Page 1 of 1

help with value of variable

Posted: Thu Sep 21, 2006 8:39 pm
by speedy33417
I have the following code:

Code: Select all

echo "<a href=\"something.php?picture=" . $currentpic . "\"><img border=\"0\" src=\"http://www.something.com/images/" . $result['picture_filename'][$currentpic] . "-thumb.jpg\" width=\"" . $width . "\" height=\"" . $height . "\"></a><br>" . "\n";
I'm using the variable $currentpic twice in the same line. At the first occurence I want it to have a value of minus one of its current value, without actually changing the value of it.
Let's say $currentpic equals 5. I want it to generate the following html code

Code: Select all

<a  href="something.php?picture=4"><img border="0" src="http://www.something.com/images/5-thumb.jpg" ........>
Thanks.

Posted: Thu Sep 21, 2006 8:56 pm
by ambivalent

Code: Select all

$currentpicLessOne = $currentpic -1;

echo "<a href=\"something.php?picture=" . $currentpicLessOne . "\"><img border=\"0\" src=\"http://www.something.com/images/" . $result['picture_filename'][$currentpic] . "-thumb.jpg\" width=\"" . $width . "\" height=\"" . $height . "\"></a><br>" . "\n";

Posted: Thu Sep 21, 2006 9:30 pm
by speedy33417
Well, yeah. I guess I could do that. :D

But I'll ask anyway. Is there anyway to calculate a different value right there?

I tried . $currentpic-1 . and . ($currentpic-1) . , but both gave me an error.

Posted: Thu Sep 21, 2006 9:41 pm
by ambivalent
If you decrement the value of $currentpic inline like that, the next reference to it will also contain the decremented value, which is not what you want, right?

Posted: Thu Sep 21, 2006 10:01 pm
by speedy33417
No, I don't want that. I'd like it to keep its value. My goal would be to echo a value that is not the value of the variable, but the value of the mathematical expression (x-1) where x is $currentpic.
x equals 5, but (x-1) equals 4.

Is there any way of doing that?