【发布时间】:2019-04-18 14:02:42
【问题描述】:
我有一个幻灯片,用户可以在其中单击一个带有箭头的按钮,指向下一个和上一个。当用户单击箭头时,我想在其中保存页面名称,以便将它们重定向到正确的页面。我还想存储一个数字,这样当用户单击上一个或下一个时,整数将保存在正确的表 userTakingModule 中,在 checkPoint 下。
执行此操作的最佳方法是什么,即在form 标记内使用button 标记?当用户单击两个箭头之一时,我已经粘贴了迄今为止尝试实现的两种方式:
a.) 将 page1.html 放在一个箭头的 action 中,将 page3.html 放在另一个箭头中,使用户返回一页
b.) 保存按钮单击,将值保存到userTakingModule 表中。
html 尝试 1.)
<div class="arrow-container">
<form style="display: inline" action="dashboard.php" method="post">
<button value="1"><i class="fas fa-arrow-circle-left"></i></button>
</form>
<form style="display: inline" action="slide2.php" method="post">
<button value="3"><i class="fas fa-arrow-circle-right"></i></button>
</form>
</div>
html 尝试 2.)
<div>
<form action ="dashboard.php" method = "POST"> <!-- However I may need this page link to change depending on whether they click forward or back -->
<label>Competition Categories</label>
<select name="checkPoint">
<option value="">Select</option>
<option value="1">Previous</option>
<option value="3">Next</option>
</select>
</fieldset>
<button name="save_check_point" type="submit" type="button">View</button>
</form>
</div>
到目前为止我的查询是这样的:
<?php
// The module ID will always be 5, as they are in the Stress & Anxiety slideshow which has an ID of 5 in the table.
$idUsers = $_SESSION['id'];
$ModuleID = 5;
$checkPoint = $_POST['checkPoint'];
// Preparing and binding my SQL query which inserts a checkpoint number into the table
$stmt = $conn->prepare ("INSERT INTO `userTakingModule` (`userTakingModuleID`, `idUsers`, `ModuleID`, `checkPoint`) VALUES (NULL, ?, ?, ?)");
$stmt->bind_param("iii", $idUsers, $ModuleID, $checkPoint);
$stmt->execute();
?>
我真的在这方面苦苦挣扎了一段时间,所以任何关于这方面的帮助都会很棒,提前谢谢你。
【问题讨论】:
-
您需要保留用户历史记录还是只保留当前位置?如果您只想存储当前位置,请在页面加载时插入(或如果当前会话的记录存在则更新)一条记录。用户是否进入下一页或上一页无关紧要,您在幻灯片页面加载时更新数据库。
-
你好@Vasya我只需要运行一个插入(或更新查询,如果一个整数已经保存在表中),当它们到达
checkPoint的特定页面时,请说你可以帮忙哈哈! -
一个简单的方法是在 $(document).ready 事件中调用 php 脚本(使用 jquery)
-
我可以将 SQL 查询包装在这个抱歉中吗?