duanfu4446 2015-10-28 16:31
浏览 26
已采纳

单击div [关闭]时加载MySQL数据

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?

  • 写回答

1条回答 默认 最新

  • dtwr2012 2015-10-28 16:38
    关注

    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..)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里