单击php(ajax?)转到下一个数组

时间:2014-11-28 11:24:58

标签: javascript php jquery arrays ajax

当我点击按钮时,我想影响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或者使用表单发布一些事情吗?

2 个答案:

答案 0 :(得分:0)

只需通过查询字符串传递数据。

<?php
    $index = intval($_GET['index']);
    if (!index) {
      $index = 1;
    }
?>
<a href="sameScript.php?index=<?php echo $index + 1; ?>">Next</a>

你可能想要比那更聪明的错误检查。

答案 1 :(得分:0)

尝试使用php之类的东西,但每次都必须携带点击值($ clickedValue)

$test_id = array('15124','26845','57845');

$current = array_search($clickedValue, $test_id);
$prevID = $test_id[$current-1];
$nextID = $test_id[$current+1];