我需要URL内保存的ID来更新数据库中的表

时间:2019-03-31 14:30:43

标签: php mysql

我在网页上有幻灯片放映,用户单击进入下一个。用户单击后,ID会在URL地址内部更改。每当用户切换到下一张幻灯片时,我都需要一种更新表的方法。我想保存用户所在的位置,以便日后重新加载其进度。幻灯片代码全部放在一个html页面中。下面的2个部分(幻灯片)的摘要:

<section class="aligncenter">
    <span class="background light" style="background-image: url('istudy_slides_images/abstract2.jpg')"/></span>
        <div class="wrap" id="slide=6">
        <div class="wrap">
             <h1>Stress is often defined as when an individual perceives the demands upon them to exceed there perceived ability to cope</h1>
        </div>
</section>

<!-- SLIDE 6 -->
<section>
    <span class="background" style="background-image:url('istudy_slides_images/balance.jpg')"></span>
          <div class="wrap" id="slide=7">
          <div class="alignright size-50 bg-trans-dark">
             <p class="text-subtitle text-serif">"In the end, it's all a question of balance" - Rohinton Mistry</p><br>
             <h3><strong>Balance</strong></h3>
             <p>A common source of stress and anxiety is when we lack balance within our lives.</p>
             <p><strong>Task Two:</strong> Consider whether you have the correct balance in you're life.<br>Are there any improvements you can make to your life work balance to improve your wellbeing?</p>
           </div>
           </div>
</section>

显示ID的URL的屏幕截图(每次ID更改时,我都可以使用它来更新数据库checkPointMod中的表吗?非常感谢任何帮助,我一直坚持使用此ID一段时间。如果最好的方法是使用cookie /会话,请有人给我一些指导吗?

URL Screenshot showing the ID

使用:Webslides.tv用于幻灯片https://webslides.tv/#slide=2

1 个答案:

答案 0 :(得分:1)

我可以提供一种通用方法,而不是确切的代码。因此,您可以执行以下操作,使用这样的JavaScript在URL中获取该哈希参数,

let slideID = window.location.hash

然后,您可以使用本地存储来存储该ID,以便您可以使用该ID将用户导航到当前的幻灯片,

localStorage.setItem('slideid', slideID);

然后在重新加载页面时,您可以像这样检索slideID

localStorage.getItem('slideid');