FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Associative Array
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Associative Array [message #176163 is a reply to message #176161] Mon, 28 November 2011 11:08 Go to previous messageGo to previous message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma:
Senior Member
On 11/28/2011 11:33 AM, Jesolo Sun wrote:
>
>
> Hi,
>
> You can solve this in different ways.
> The easiest is probably sending the values for ProductID and "Product
> variant".
>
> So in your form add:
> <INPUT type="hidden" name="productid"
> value="<?php echo $usedproductid; ?>">
> <INPUT type="hidden" name="productvariant"
> value="<?php echo $usedproductvariant; ?>">
>
> Of course, use something sensible for $usedproductid and
> $usedproductvariant.
>
> Next, from your receiving script:
> $productid = (int)$_POST["productid"];
> $productvariant = (int)$_POST["productvariant"];
>
> and use them by replacing the 99 and 300 in the original (form Jerry's
> example):
>
> $val0 = $_POST['product_data'][$productid ][$productvariant]['prezzo0'];
> // 2.20
> $val1 = $_POST['product_data'][$productid ][$productvariant]['prezzo1'];
> // empty string
>
> Regards,
> Erwin Moller
>

[fixed posting somewhat. Please do *not* answer UNDER a sig. Use a
newsreader please.]

>
> Hi
> is not possible because in the first page i use this values in Javascript functions for example : calculate(numero_99_300, 99, 300);
> this input
> <INPUT style="width: 130px;" id="99_300_numero0"
onChange="if (this.value < min_numero_per_calcolare) {
$(window).humanMsg('Minimal, total quantity of products has to be: '
+ min_numero_per_calcolare + ' pcs.'); this.value = ''; return false
}change_colour('99','300','0',this);document.getElementById('99_300_il0').v alue
= this.value;cambio_pagamento('99','300');calculate(numero_99_300, 99,
300);"
> class="formfield" name="product_data[99][300][numero0]" type="text">


I don't know how you set up you logic on the client.
But from the looks of it you are not experienced in Javascript. It looks
very messy to me. :-(

Anyway, if you want to solve it serverside you can also try something
like this:
Assuming you have the folowwing structure:
$_POST['product_data'][..productid..][..productvariant..]

and you post something that arrives as:
$_POST['product_data'][123][987]['prezzo0']

$allKeys = array_keys($_POST['product_data'])
Now $allKeys will contains an array with 123.

If you post multiple productdata, that arrive like this:
$_POST['product_data'][123][123]['prezzo0']
$_POST['product_data'][22][165]['prezzo0']

Then $allKeys will contains an array with 123 AND 22.

Read more here:
http://nl2.php.net/manual/en/function.array-keys.php

Alternatively you can use foreach as here under:
foreach ($_POST['product_data'] as $aProductKey => $productInfo){
// $aProductKey now 123
}

You can do the same productinfo.

Hope that helps, but I would advice you to make better better use of
Javascript, because that is an easier approach. (And stay away from JQuery)

Good luck.

Regards,
Erwin Moller

--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Order/Timing of Execution of PHP
Next Topic: Browser doesn't support
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 10:49:39 GMT 2024

Total time taken to generate the page: 0.06820 seconds