我想在单击按钮时影响 php:(我知道客户端和服务器端之间的区别。但我很确定已经看到了类似的东西。
我有这个数组:
$test_id = [
1 => '15124'
2 => '26845'
3 => '57845'
....
];
echo current($test_id);
echo '<input type="submit" name="next" value="next">';
我希望每次单击按钮时都按照 id 的顺序回显下一个titlte_id。
我知道我将不得不用ajax或表单帖子做点什么?
只需通过查询字符串传递数据。
<?php
$index = intval($_GET['index']);
if (!index) {
$index = 1;
}
?>
<a href="sameScript.php?index=<?php echo $index + 1; ?>">Next</a>
不过,您可能需要比这更智能的错误检查。
尝试用
php 做类似的事情,但你必须每次都携带点击值($clickedValue)
$test_id = array('15124','26845','57845');
$current = array_search($clickedValue, $test_id);
$prevID = $test_id[$current-1];
$nextID = $test_id[$current+1];