I am making a system where the user can select game characters he has (characters stored in another table). If he has 2 characters, he should see two div's with the data of characters in that div - etc.
I know how to make the divs, but how can I load that specific character data he clicked to the users SESSION? For example he pressed character number 2, how do I know he selected the 2nd character he has in the database?
The problem is that every user might have different amount of divs, how do I know which data should I load to the session and continue with the code. I hope you understand my request. Do I somehow assign a number to each div?
Each of your chars in the database should have a unique id, which identifies him (primary key with auto increment). So get the click, you could add a <a>
tag arround the div which do the redirect and handles the selection of your character
<a href="selectChar.php?char=<?php echo $char['id']; ?>">
<div>..</div>
</a>
So if you click on the div, the selectChar.php script is called with the get param char
. This param could be accessed with $_GET
.
$char_id = $_GET['char'];
and with this id you would find the char in your database and save it to the session (or do whatever you want with it..)