help with value of variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

help with value of variable

Post 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.
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post 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";
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

Post 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.
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post 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?
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

Post 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?
Post Reply