0

I have a url like this

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.....

that sends to a page the values of a shopping card. I want to GET the values item_name_x, quantity_x, amount_x where x the number of each product, group and print them like

Product 1 name - Product 1 Quantity - Product 1 Amount
Product 2 name - Product 2 Quantity - Product 2 Amount
Product 3 name - Product 3 Quantity - Product 3 Amount
......

I can't make any change to the page who produce the url. Can anyone help me? Thanks in advance for any help you are able to provide.

3
  • Can you show the code you tried making this work with? Commented May 4, 2015 at 11:08
  • So... you want to do a simple $_GET['productname'] and so on? Commented May 4, 2015 at 11:08
  • I tried '$_GET["item_name_1"]' etc but every time the number of products in url is different and i don't know how to get the values for different number of products. Commented May 4, 2015 at 11:12

2 Answers 2

3

That's a really bad design, poor you have to deal with it. However, if you're sure that the query string will always be consistent (i.e.: each group will always be complete: name-quantity-amount) you can try this:

$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++;
}
Sign up to request clarification or add additional context in comments.

Comments

0

what about this

<?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 }?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.