Greetings,
I just started coding PHP 2 days ago. I decided that I would make some PHP Based PHP.
To do so I first used imagecopy to make myself an “avatar system” that looks like this :
hxxp://website.com/avatar.php?skin=1&armor=1&hat=1&face=1&item1=1&item2=1&hair=1
There will belong the names of the png images that will be used to display the various items. I name give them numbers names because at a later time, once I am more skilled, I will make an item table into mysql and make PHP fetch into this table.
Meanwhile, I am building my registration page on which I want users to be able to set their characters.
http://img1.uploadscreenshot.com/images/orig/3/8012253478-orig.jpg
In order to make this thing work, I decided to pick a pre-made JS script on the internet… it seemed easier, and I didn’t want to bother too much on this part of my project lol. So, it looks like this :
[code]function sumhair() {
document.getElementsByName(“avatar”)[0].setAttribute(“src”, “avatar.php?skin=1&armor=1&hat=1&face=1&item1=1&item2=1&hair=<? echo ++$un; ?>”);
}
function neghair() {
document.getElementsByName(“avatar”)[0].setAttribute(“src”, “avatar.php?skin=1&armor=1&hat=1&face=1&item1=1&item2=1&hair=<? echo --$un; ?>”);
}[/code]
I would have JS codes of eachs defining functions for increament and decreament for the arrow buttons.
<input value=">>" name="next_hair" type="button" onClick="sumhair()"/>
<input value="<<" name="next_hair" type="button" onClick="neghair()"/>
Setted up through an included js file. Okayyyyy… So! Here is my issue. I do not understand how increamentation works. I do want to make incrementing buttons for my avatar design, so it switch items. I tried the following as of now :
[php]$un = 1;
<? echo ++$un; ?> // This being used in the links written within JS script[/php]But I get stuck at 2. It seems $un + 1 = 2. Then if I press my button again… ++$un is still understood as " 1 + 1 = 2 " and not as " 2 + 1= 3 ", which is what I want as result. Can somebody help me understand how to deal with this issue? Perhaps should I make some function? Hmmm… I am somewhat lost there.