-2

例如,我有一个li,每个li人都有一个<a>
这是我的代码。

include 'functions/class.php';

$db = new DB();
$warriors = array();
$result=$db->getWarriors();

foreach($result as $names) {
    echo '<li><a href="display_warrior.php id='.$names['warrior_id'].'">'.$names['warrior_name'].'</a></li>';
}

我想要发生的情况是,例如,当我单击特定链接时,它从我的数据库中显示 3 个值,它的 id 将直接转到一个数组,当我单击另一个 a 时,它会添加到数组中,因此我的数组中已经有 2 个值如何我可以这样做吗?

检索值

if(isset($_GET['id'])) {
    $values = array($_GET['id']);//it overwrites how to do the right way?
}
4

1 回答 1

2

I think you're looking for this instead:

if(isset($_GET['id'])) {
    $values['id'] = $_GET['id'];
}

Update

Is this what you want?

<?php
    if (!empty($_GET["values"])) {
        $currentOptionsArray = explode(",", $_GET["values"]);
        $currentOptionsText = implode(",", $currentOptionsArray) . ",";
    } else {
        $currentOptionsText = "";
    }
?>
<a href="?values=<?=$currentOptionsText?>option1">Option 1</a>
<a href="?values=<?=$currentOptionsText?>option2">Option 2</a>
<a href="?values=<?=$currentOptionsText?>option3">Option 3</a>
于 2012-09-12T08:58:14.610 回答