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 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?