2012-09-12 38 views
-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將直接進入到一個數組,當我點擊另一個就那麼有添加到陣列我的數組中已經有2個值了,我該怎麼做?

檢索值

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

你在找會議..? – deceze

+0

我想要發生的是,例如我點擊名稱1,並有一個ID爲N0001,我點擊名稱2有一個ID爲N0002,所以在我的數組中,我有N0001和N0001是可能的嗎? –

+0

是的,這是可能的。再一次,你可能正在尋找**會議**。找到關於這些的教程。 – deceze

回答

2

我認爲你正在尋找這個代替:

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

更新

這是你想要的嗎?

<?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> 
+0

它仍然覆蓋,我想發生的是,例如我點擊名稱1,並有一個ID爲N0001,我點擊名稱2有一個ID爲N0002所以在我的數組中,我有N0001和N0001是可能的嗎? –

+0

@BrainedWashed我更新了我的評論 - 這是你想要的? – h2ooooooo

相關問題