2015-05-04 136 views
0

我有這樣如何在PHP中獲取多個值?

http://example.com/index.php?&item_name_1=productnamex&quantity_1=1&amount_1=0&item_number_1=2&on0_2=thumb&option_index_2=1&item_name_2=productnamex&quantity_2=1&amount_2=0&item_number_2=2&on0_2=thumb&option_index_2=1&item_name_3=productnamexx&quantity_3=1&amount_3=0&item_number_3=3&on0_3=thumb&option_index_3=1.....

發送到頁面的購物卡的值的網址。我想要得到的值item_name_x,quantity_x,amount_x其中X每一個產品,組的數量和打印他們像

產品1名 - 第1個數量 - 產品1個金額
產品2名 - 第2數量 - 產品2金額
產品3名稱 - 產品3數量 - 產品3金額
......

我無法對產生網址的頁面進行任何更改。 任何人都可以幫助我嗎? 預先感謝您能夠提供的任何幫助。

+0

您可以顯示您嘗試的代碼這項工作與? – RST

+0

所以......你想要做一個簡單的$ _GET ['productname']等等? – Epodax

+0

我試過'$ _GET [「item_name_1」]'等,但每次在url中的產品數量是不同的,我不知道如何獲得不同數量的產品的值。 – Chris

回答

3

這是一個非常糟糕的設計,可憐的你必須處理它。但是,如果您確定查詢字符串始終保持一致(即:每個組將始終完整:名稱數量金額),您可以試試這個:

$i = 1; 
while (isset($_GET['item_name_'.$i])) { 
    $name = $_GET['item_name_'.$i]; 
    $qty = $_GET['quantity_'.$i]; 
    $amt = $_GET['amount_'.$i]; 
    ... // do whatever you want with those 3 
    $i++; 
} 
+0

它的工作,謝謝。 – Chris

0

這個怎麼

<?php 
$count=count($_GET); 
for($i=1;$i=$count;$i++) 
{?> 
Product <?php $i;?> name - Product <?php echo $i?> Quantity - Product <?php echo $i?> Amount 
<?php }?>