Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3937 > unrolled thread

Associative Array

Started by"Jesolo Sun" <gala@tiscali.it>
First post2011-11-26 01:37 +0100
Last post2011-11-28 16:39 +0100
Articles 20 on this page of 22 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  Associative Array "Jesolo Sun" <gala@tiscali.it> - 2011-11-26 01:37 +0100
    Re: Associative Array Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-25 19:55 -0500
      Re: Associative Array "Jesolo Sun" <gala@tiscali.it> - 2011-11-26 09:01 +0100
        Re: Associative Array Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-26 05:01 -0500
        Re: Associative Array Norman Peelman <npeelmandog@cfl.rr.com> - 2011-11-26 07:55 -0500
          Re: Associative Array "Jesolo Sun" <gala@tiscali.it> - 2011-11-28 10:42 +0100
        Re: Associative Array Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-26 10:28 -0500
          Re: Associative Array "Jesolo Sun" <gala@tiscali.it> - 2011-11-28 10:41 +0100
            Re: Associative Array Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-11-28 11:11 +0100
              Re: Associative Array "Jesolo Sun" <gala@tiscali.it> - 2011-11-28 11:33 +0100
                Re: Associative Array Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-11-28 12:08 +0100
                Re: Associative Array Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-28 07:27 -0500
                  Re: Associative Array Cristiano Larghi <c.larghi@criosoftware.it> - 2011-11-28 12:41 +0000
                    Re: Associative Array "Jesolo Sun" <gala@tiscali.it> - 2011-11-28 14:48 +0100
                    Re: Associative Array Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-28 13:57 -0500
                      Re: Associative Array Doug Miller <doug_at_milmacdotcom@example.com> - 2011-11-28 15:42 -0500
                        Re: Associative Array Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-28 16:00 -0500
                          Re: Associative Array Doug Miller <doug_at_milmacdotcom@example.com> - 2011-11-28 18:26 -0500
                            Re: Associative Array Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-28 21:03 -0500
                  Re: Associative Array "Jesolo Sun" <gala@tiscali.it> - 2011-11-28 14:31 +0100
                  Re: Associative Array "Jesolo Sun" <gala@tiscali.it> - 2011-11-28 15:59 +0100
                    Re: Associative Array Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-11-28 16:39 +0100

Page 1 of 2  [1] 2  Next page →


#3937 — Associative Array

From"Jesolo Sun" <gala@tiscali.it>
Date2011-11-26 01:37 +0100
SubjectAssociative Array
Message-ID<4ed034c2$0$1384$4fafbaef@reader1.news.tin.it>
I have variuous selectbox a inputbox radio e checkbox  

<INPUT id="99_300_prezzo0"  name="product_data[99][300][prezzo0]" 
readOnly="readonly" type="text">
<INPUT id="99_300_prezzo1"  name="product_data[99][300][prezzo1]" 
readOnly="readonly" type="text">
<INPUT id="99_300_prezzo2"  name="product_data[99][300][prezzo2]" 
readOnly="readonly" type="text">

Check this data from $_POST 

print_r ($_POST);

and wtite :
Array ( [product_data] =>
    Array ( [99] =>
    Array ( [300] =>
    Array ( [prezzo0] => 2.20
    [prezzo1] =>
    [prezzo2] =>
    [prezzocal0] => 238.03
    [prezzocal1] =>
    [prezzocal2] =>
    [numero0] => 108
    [numero1] =>
    [numero2] =>
    [color] => 64
    [tipo_stampa] => 4_0
    [il_colore0] => 1
    [il_colore1] => 1
    [il_colore2] => 1
    [adornment] =>
        Array ( [0] => 11 [1] => 12 )
    [pacchetto_id] => 136#P_701
    [colorepack] => 74#P_701_E
    [realization_period] => N ) ) ) [submit] => Conferma ordine )



$array = $_POST;

for ($i=0;$i<count($array)-1;$i++)
{
 
  for ($a=$i+1;$a<count($array);$a++)
  {
      
      for ($b=$i+1;$b<count($array);$b++)
      {

          for ($c=$i+1;$c<count($array);$c++)
          {
    
            print $Colore = $_POST['color']."<br>";
            
            $ordina = strcmp($array[$i]["device"], $array[$c]["device"]);
        
            if ($ordina > 0)
            {
              $ordinato = $array[$i];
              $array[$i] = $array[$a];
              $array[$a] = $array[$b];
              $array[$b] = $array[$c];
              $array[$c] = $ordinato;
            }
        }
     }
  }
}

echo "<pre>\n";
print_r($array);
echo "</pre>\n";


Array
(
    [product_data] => Array
        (
            [99] => Array
                (
                    [300] => Array
                        (
                            [prezzo0] => 2.22
                            [prezzo1] => 
                            [prezzo2] => 
                            [prezzoAa0] => 239.26
                            [prezzocal1] => 
                            [prezzocal2] => 
                            [numero0] => 108
                            [numero1] => 
                            [numero2] => 
                            [color] => 39
                            [tipo_stampa] => 4_1
                            [il_colore0] => 1
                            [il_colore1] => 1
                            [il_colore2] => 1
                            [ad_adornment] => Array
                                (
                                    [0] => 11
                                    [1] => 13
                                )

                            [pacchetto_id] => 136#P_701 
                            [colorepack] => 45#P_701_D
                            [realization_period] => N
                        )

                )

        )

    [submit] => Conferma ordine )


5 Array ...
How do I recover my data to manage them?


[toc] | [next] | [standalone]


#3938

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-11-25 19:55 -0500
Message-ID<japdds$g99$1@dont-email.me>
In reply to#3937
On 11/25/2011 7:37 PM, Jesolo Sun wrote:
>
> I have variuous selectbox a inputbox radio e checkbox
> <INPUT id="99_300_prezzo0" name="product_data[99][300][prezzo0]"
> readOnly="readonly" type="text">
> <INPUT id="99_300_prezzo1" name="product_data[99][300][prezzo1]"
> readOnly="readonly" type="text">
> <INPUT id="99_300_prezzo2" name="product_data[99][300][prezzo2]"
> readOnly="readonly" type="text">
>
> Check this data from $_POST
> print_r ($_POST);
>
> and wtite :
> Array ( [product_data] =>
> Array ( [99] =>
> Array ( [300] =>
> Array ( [prezzo0] => 2.20
> [prezzo1] =>
> [prezzo2] =>
> [prezzocal0] => 238.03
> [prezzocal1] =>
> [prezzocal2] =>
> [numero0] => 108
> [numero1] =>
> [numero2] =>
> [color] => 64
> [tipo_stampa] => 4_0
> [il_colore0] => 1
> [il_colore1] => 1
> [il_colore2] => 1
> [adornment] =>
> Array ( [0] => 11 [1] => 12 )
> [pacchetto_id] => 136#P_701
> [colorepack] => 74#P_701_E
> [realization_period] => N ) ) ) [submit] => Conferma ordine )
>
>
>
> $array = $_POST;
>
> for ($i=0;$i<count($array)-1;$i++)
> {
>
> for ($a=$i+1;$a<count($array);$a++)
> {
> for ($b=$i+1;$b<count($array);$b++)
> {
>
> for ($c=$i+1;$c<count($array);$c++)
> {
> print $Colore = $_POST['color']."<br>";
> $ordina = strcmp($array[$i]["device"], $array[$c]["device"]);
> if ($ordina > 0)
> {
> $ordinato = $array[$i];
> $array[$i] = $array[$a];
> $array[$a] = $array[$b];
> $array[$b] = $array[$c];
> $array[$c] = $ordinato;
> }
> }
> }
> }
> }
>
> echo "<pre>\n";
> print_r($array);
> echo "</pre>\n";
>
>
> Array
> (
> [product_data] => Array
> (
> [99] => Array
> (
> [300] => Array
> (
> [prezzo0] => 2.22
> [prezzo1] => [prezzo2] => [prezzoAa0] => 239.26
> [prezzocal1] => [prezzocal2] => [numero0] => 108
> [numero1] => [numero2] => [color] => 39
> [tipo_stampa] => 4_1
> [il_colore0] => 1
> [il_colore1] => 1
> [il_colore2] => 1
> [ad_adornment] => Array
> (
> [0] => 11
> [1] => 13
> )
>
> [pacchetto_id] => 136#P_701 [colorepack] => 45#P_701_D
> [realization_period] => N
> )
>
> )
>
> )
>
> [submit] => Conferma ordine )
>
>
> 5 Array ...
> How do I recover my data to manage them?
>
>
>

I don't understand your problem.  Please forget the code and state it 
succinctly.  It will be much easier for us to help you.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3939

From"Jesolo Sun" <gala@tiscali.it>
Date2011-11-26 09:01 +0100
Message-ID<4ed09cbf$0$1384$4fafbaef@reader1.news.tin.it>
In reply to#3938

"Jerry Stuckle"  ha scritto nel messaggio news:japdds$g99$1@dont-email.me...

On 11/25/2011 7:37 PM, Jesolo Sun wrote:


SORRY......

Data FROM POST
print_r ($_POST);


Array ( [product_data] =>
    Array ( [99] =>
    Array ( [300] =>
    Array ( [prezzo0] => 2.20
    [prezzo1] =>
    [prezzo2] =>
    [prezzocal0] => 238.03
    [prezzocal1] =>
    [prezzocal2] =>
    [numero0] => 108
    [numero1] =>
    [numero2] =>
    [color] => 64
    [tipo_stampa] => 4_0
    [il_colore0] => 1
    [il_colore1] => 1
    [il_colore2] => 1
    [adornment] =>
        Array ( [0] => 11 [1] => 12 )
    [pacchetto_id] => 136#P_701
    [colorepack] => 74#P_701_E
    [realization_period] => N ) ) ) [submit] => Conferma ordine )

I need this data
How? 

[toc] | [prev] | [next] | [standalone]


#3940

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-11-26 05:01 -0500
Message-ID<jaqddv$sul$1@dont-email.me>
In reply to#3939
On 11/26/2011 3:01 AM, Jesolo Sun wrote:
>
>
> "Jerry Stuckle" ha scritto nel messaggio news:japdds$g99$1@dont-email.me...
>
> On 11/25/2011 7:37 PM, Jesolo Sun wrote:
>
>
> SORRY......
>
> Data FROM POST
> print_r ($_POST);
>
>
> Array ( [product_data] =>
> Array ( [99] =>
> Array ( [300] =>
> Array ( [prezzo0] => 2.20
> [prezzo1] =>
> [prezzo2] =>
> [prezzocal0] => 238.03
> [prezzocal1] =>
> [prezzocal2] =>
> [numero0] => 108
> [numero1] =>
> [numero2] =>
> [color] => 64
> [tipo_stampa] => 4_0
> [il_colore0] => 1
> [il_colore1] => 1
> [il_colore2] => 1
> [adornment] =>
> Array ( [0] => 11 [1] => 12 )
> [pacchetto_id] => 136#P_701
> [colorepack] => 74#P_701_E
> [realization_period] => N ) ) ) [submit] => Conferma ordine )
>
> I need this data
> How?

The data is in your $_POST superglobal.  Again, what's your problem?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3943

FromNorman Peelman <npeelmandog@cfl.rr.com>
Date2011-11-26 07:55 -0500
Message-ID<jaqnkm$iom$1@dont-email.me>
In reply to#3939
On 11/26/2011 03:01 AM, Jesolo Sun wrote:
>
>
> "Jerry Stuckle" ha scritto nel messaggio news:japdds$g99$1@dont-email.me...
>
> On 11/25/2011 7:37 PM, Jesolo Sun wrote:
>
>
> SORRY......
>
> Data FROM POST
> print_r ($_POST);
>
>
> Array ( [product_data] =>
> Array ( [99] =>
> Array ( [300] =>
> Array ( [prezzo0] => 2.20
> [prezzo1] =>
> [prezzo2] =>
> [prezzocal0] => 238.03
> [prezzocal1] =>
> [prezzocal2] =>
> [numero0] => 108
> [numero1] =>
> [numero2] =>
> [color] => 64
> [tipo_stampa] => 4_0
> [il_colore0] => 1
> [il_colore1] => 1
> [il_colore2] => 1
> [adornment] =>
> Array ( [0] => 11 [1] => 12 )
> [pacchetto_id] => 136#P_701
> [colorepack] => 74#P_701_E
> [realization_period] => N ) ) ) [submit] => Conferma ordine )
>
> I need this data
> How?

   Like Jerry said, you have the data in $_POST. Do you need to know 
what data is there?

   I see you have a variable structure as:

$product_data[n][m][?]

... so I assume you need to know what [n], [m] and [?] are when a user 
submits the form. Take a look at the array functions:


http://us.php.net/manual/en/ref.array.php

http://us.php.net/manual/en/function.array-keys.php#73992
http://us.php.net/manual/en/function.array-keys.php#29165


-- 
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-

[toc] | [prev] | [next] | [standalone]


#3955

From"Jesolo Sun" <gala@tiscali.it>
Date2011-11-28 10:42 +0100
Message-ID<4ed3578c$0$1389$4fafbaef@reader1.news.tin.it>
In reply to#3943
> How?

   Like Jerry said, you have the data in $_POST. Do you need to know 
what data is there?

   I see you have a variable structure as:

$product_data[n][m][?]

... so I assume you need to know what [n], [m] and [?] are when a user 
submits the form. Take a look at the array functions:


http://us.php.net/manual/en/ref.array.php

http://us.php.net/manual/en/function.array-keys.php#73992
http://us.php.net/manual/en/function.array-keys.php#29165


-- 
Dear Norman
i have used this example 
http://us.php.net/manual/en/function.array-keys.php#73992:

the response of Array is this
Array
(
    [0] => 0
    [1] => product_data
    [2] => 99
    [3] => 300
    [4] => prezzo0
    [5] => prezzo1
    [6] => prezzo2
    [7] => prezzocal0
    [8] => prezzocal1
    [9] => prezzocal2
    [10] => numero0
    [11] => numero1
    [12] => numero2
    [13] => color
    [14] => tipo_stampa
    [15] => il_colore0
    [16] => il_colore1
    [17] => il_colore2
    [18] => ad_adornment
    [19] => 0
    [20] => 1
    [21] => 2
    [22] => 3
    [23] => pacchetto_id
    [24] => colorepack
    [25] => realization_period
    [26] => submit
)

question:
how get this values?

example
$val0 = [2] => 99
$val1 = [4] => prezzo0
$val1 = [14] => tipo_stampa

?? 

[toc] | [prev] | [next] | [standalone]


#3944

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-11-26 10:28 -0500
Message-ID<jar0ic$8mq$1@dont-email.me>
In reply to#3939
On 11/26/2011 3:01 AM, Jesolo Sun wrote:
>
>
> "Jerry Stuckle" ha scritto nel messaggio news:japdds$g99$1@dont-email.me...
>
> On 11/25/2011 7:37 PM, Jesolo Sun wrote:
>
>
> SORRY......
>
> Data FROM POST
> print_r ($_POST);
>
>
> Array ( [product_data] =>
> Array ( [99] =>
> Array ( [300] =>
> Array ( [prezzo0] => 2.20
> [prezzo1] =>
> [prezzo2] =>
> [prezzocal0] => 238.03
> [prezzocal1] =>
> [prezzocal2] =>
> [numero0] => 108
> [numero1] =>
> [numero2] =>
> [color] => 64
> [tipo_stampa] => 4_0
> [il_colore0] => 1
> [il_colore1] => 1
> [il_colore2] => 1
> [adornment] =>
> Array ( [0] => 11 [1] => 12 )
> [pacchetto_id] => 136#P_701
> [colorepack] => 74#P_701_E
> [realization_period] => N ) ) ) [submit] => Conferma ordine )
>
> I need this data
> How?

I'm sorry, Jesolo, I understand English isn't your first language and 
you're trying to communicate your problem.  But reading through both of 
your posts again, I'm just not understanding what your problem is.

The data is in your $_POST array, and all accessible to your script. 
You do have multiple dimensional arrays in your $_POST array, but you 
access it similar to in your HTML, i.e.

$val0 = $_POST['product_data'][99][300]['prezzo0'];  // 2.20
$val1 = $_POST['product_data'][99][300]['prezzo1'];  // empty string

and so on.

Is this your problem?
-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3954

From"Jesolo Sun" <gala@tiscali.it>
Date2011-11-28 10:41 +0100
Message-ID<4ed35749$0$1374$4fafbaef@reader1.news.tin.it>
In reply to#3944
?

I'm sorry, Jesolo, I understand English isn't your first language and
you're trying to communicate your problem.  But reading through both of
your posts again, I'm just not understanding what your problem is.

The data is in your $_POST array, and all accessible to your script.
You do have multiple dimensional arrays in your $_POST array, but you
access it similar to in your HTML, i.e.

$val0 = $_POST['product_data'][99][300]['prezzo0'];  // 2.20
$val1 = $_POST['product_data'][99][300]['prezzo1'];  // empty string

and so on.

Is this your problem?



Dear sirs
i have used this and get the values
my problem is the values in the POST, the value  [99] is dynamics ( this is
ProductID) and  [300] is dynamics ( this is Product variant)
For every product i have different ProductID and different Product variant 

[toc] | [prev] | [next] | [standalone]


#3956

FromErwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com>
Date2011-11-28 11:11 +0100
Message-ID<4ed35e4b$0$6887$e4fe514c@news2.news.xs4all.nl>
In reply to#3954
On 11/28/2011 10:41 AM, Jesolo Sun wrote:
> ?
>
> I'm sorry, Jesolo, I understand English isn't your first language and
> you're trying to communicate your problem. But reading through both of
> your posts again, I'm just not understanding what your problem is.
>
> The data is in your $_POST array, and all accessible to your script.
> You do have multiple dimensional arrays in your $_POST array, but you
> access it similar to in your HTML, i.e.
>
> $val0 = $_POST['product_data'][99][300]['prezzo0']; // 2.20
> $val1 = $_POST['product_data'][99][300]['prezzo1']; // empty string
>
> and so on.
>
> Is this your problem?
>
>
>
> Dear sirs
> i have used this and get the values
> my problem is the values in the POST, the value [99] is dynamics ( this is
> ProductID) and [300] is dynamics ( this is Product variant)
> For every product i have different ProductID and different Product variant

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

-- 
"That which can be asserted without evidence, can be dismissed without 
evidence."
-- Christopher Hitchens

[toc] | [prev] | [next] | [standalone]


#3957

From"Jesolo Sun" <gala@tiscali.it>
Date2011-11-28 11:33 +0100
Message-ID<4ed3638d$0$1387$4fafbaef@reader1.news.tin.it>
In reply to#3956

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

-- 
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens


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').value 
= this.value;cambio_pagamento('99','300');calculate(numero_99_300, 99, 
300);"
                                                   class="formfield" 
name="product_data[99][300][numero0]" type="text">





[toc] | [prev] | [next] | [standalone]


#3959

FromErwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com>
Date2011-11-28 12:08 +0100
Message-ID<4ed36bb8$0$6984$e4fe514c@news2.news.xs4all.nl>
In reply to#3957
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').value 
= 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

[toc] | [prev] | [next] | [standalone]


#3960

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-11-28 07:27 -0500
Message-ID<javunb$78b$1@dont-email.me>
In reply to#3957
On 11/28/2011 5:33 AM, Jesolo Sun wrote:
> 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').value
> = this.value;cambio_pagamento('99','300');calculate(numero_99_300, 99,
> 300);"
>                                                    class="formfield"
> name="product_data[99][300][numero0]" type="text">

I agree with Erwin that using hidden fields will solve your problem, and 
I see no reason they should affect your javascript.  It would require 
the least modification to your page.  Using PHP's array functions is 
also a solution.

A good start would be to check out foreach(), i.e.

foreach($array = $key=>$value)

You could use this as

foreach ($_POST['product_data'] as $product_id=>$prod_data)
   foreach ($prod_data as $product_variant=>$variant_data)

But I also think your approach can be confusing.  Better I would think 
would be to just use product_data[0], product_data[1], etc, with a 
hidden field containing id, i.e.

<input type="hidden" name="product_data[0][id]" value="99"> (product id)
<input type="hidden" name="product_data[0][0]" value="300"> (variant)
<INPUT id="99_300_prezzo0"  name="product_data[0][0][0]"
    readOnly="readonly" type="text">  (value for prezzo0)
<INPUT id="99_300_prezzo1"  name="product_data[0][0][1]"
    readOnly="readonly" type="text">  (value for prezzo1)

And so on.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3961

FromCristiano Larghi <c.larghi@criosoftware.it>
Date2011-11-28 12:41 +0000
Message-ID<javvii$j6v$1@dont-email.me>
In reply to#3960
Il Mon, 28 Nov 2011 07:27:16 -0500, Jerry Stuckle ha scritto:

> <INPUT id="99_300_prezzo0"  name="product_data[0][0][0]"
>     readOnly="readonly" type="text">  (value for prezzo0)

id (and name) *CANNOT* start with a digit ...

 http://www.w3.org/TR/html4/types.html#type-name

[toc] | [prev] | [next] | [standalone]


#3964

From"Jesolo Sun" <gala@tiscali.it>
Date2011-11-28 14:48 +0100
Message-ID<4ed39115$0$1383$4fafbaef@reader2.news.tin.it>
In reply to#3961

"Cristiano Larghi"  ha scritto nel messaggio 
news:javvii$j6v$1@dont-email.me...

Il Mon, 28 Nov 2011 07:27:16 -0500, Jerry Stuckle ha scritto:

> <INPUT id="99_300_prezzo0"  name="product_data[0][0][0]"
>     readOnly="readonly" type="text">  (value for prezzo0)

id (and name) *CANNOT* start with a digit ...

http://www.w3.org/TR/html4/types.html#type-name


Modified.....


Grazie dell'aiuto
Thanks for help me 

[toc] | [prev] | [next] | [standalone]


#3967

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-11-28 13:57 -0500
Message-ID<jb0ljd$tnt$1@dont-email.me>
In reply to#3961
On 11/28/2011 7:41 AM, Cristiano Larghi wrote:
> Il Mon, 28 Nov 2011 07:27:16 -0500, Jerry Stuckle ha scritto:
>
>> <INPUT id="99_300_prezzo0"  name="product_data[0][0][0]"
>>      readOnly="readonly" type="text">   (value for prezzo0)
>
> id (and name) *CANNOT* start with a digit ...
>
>   http://www.w3.org/TR/html4/types.html#type-name

PHP doesn't care...

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3968

FromDoug Miller <doug_at_milmacdotcom@example.com>
Date2011-11-28 15:42 -0500
Message-ID<jb0rni$bld$1@dont-email.me>
In reply to#3967
On 11/28/2011 1:57 PM, Jerry Stuckle wrote:
> On 11/28/2011 7:41 AM, Cristiano Larghi wrote:
>> Il Mon, 28 Nov 2011 07:27:16 -0500, Jerry Stuckle ha scritto:
>>
>>> <INPUT id="99_300_prezzo0" name="product_data[0][0][0]"
>>> readOnly="readonly" type="text"> (value for prezzo0)
>>
>> id (and name) *CANNOT* start with a digit ...
>>
>> http://www.w3.org/TR/html4/types.html#type-name
>
> PHP doesn't care...
>
Except to the extent that the HTML error may affect the way the browser 
presents the $_POST array to the server. The original post isn't 
available to me any more, but IIRC it showed that his $_POST array had 
*three* elements where he really wanted only one, e.g.
$_POST ['99']
$_POST ['300']
$_POST ['prezzo0']
where he was expecting to see
$_POST ['99_300_prezzo0']

ISTM that he may not have had this problem had the HTML code read
<INPUT id="A_99_ ... etc.

[toc] | [prev] | [next] | [standalone]


#3969

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-11-28 16:00 -0500
Message-ID<jb0sph$j6b$1@dont-email.me>
In reply to#3968
On 11/28/2011 3:42 PM, Doug Miller wrote:
> On 11/28/2011 1:57 PM, Jerry Stuckle wrote:
>> On 11/28/2011 7:41 AM, Cristiano Larghi wrote:
>>> Il Mon, 28 Nov 2011 07:27:16 -0500, Jerry Stuckle ha scritto:
>>>
>>>> <INPUT id="99_300_prezzo0" name="product_data[0][0][0]"
>>>> readOnly="readonly" type="text"> (value for prezzo0)
>>>
>>> id (and name) *CANNOT* start with a digit ...
>>>
>>> http://www.w3.org/TR/html4/types.html#type-name
>>
>> PHP doesn't care...
>>
> Except to the extent that the HTML error may affect the way the browser
> presents the $_POST array to the server. The original post isn't
> available to me any more, but IIRC it showed that his $_POST array had
> *three* elements where he really wanted only one, e.g.
> $_POST ['99']
> $_POST ['300']
> $_POST ['prezzo0']
> where he was expecting to see
> $_POST ['99_300_prezzo0']
>
> ISTM that he may not have had this problem had the HTML code read
> <INPUT id="A_99_ ... etc.

PHP doesn't care...

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3970

FromDoug Miller <doug_at_milmacdotcom@example.com>
Date2011-11-28 18:26 -0500
Message-ID<jb15b3$aam$1@dont-email.me>
In reply to#3969
On 11/28/2011 4:00 PM, Jerry Stuckle wrote:
> On 11/28/2011 3:42 PM, Doug Miller wrote:
>> On 11/28/2011 1:57 PM, Jerry Stuckle wrote:
>>> On 11/28/2011 7:41 AM, Cristiano Larghi wrote:
>>>> Il Mon, 28 Nov 2011 07:27:16 -0500, Jerry Stuckle ha scritto:
>>>>
>>>>> <INPUT id="99_300_prezzo0" name="product_data[0][0][0]"
>>>>> readOnly="readonly" type="text"> (value for prezzo0)
>>>>
>>>> id (and name) *CANNOT* start with a digit ...
>>>>
>>>> http://www.w3.org/TR/html4/types.html#type-name
>>>
>>> PHP doesn't care...
>>>
>> Except to the extent that the HTML error may affect the way the browser
>> presents the $_POST array to the server. The original post isn't
>> available to me any more, but IIRC it showed that his $_POST array had
>> *three* elements where he really wanted only one, e.g.
>> $_POST ['99']
>> $_POST ['300']
>> $_POST ['prezzo0']
>> where he was expecting to see
>> $_POST ['99_300_prezzo0']
>>
>> ISTM that he may not have had this problem had the HTML code read
>> <INPUT id="A_99_ ... etc.
>
> PHP doesn't care...
>
Except to the extent that markup errors [apparently] affect the way the 
$_POST array is presented to the script...

[toc] | [prev] | [next] | [standalone]


#3971

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-11-28 21:03 -0500
Message-ID<jb1egs$vok$1@dont-email.me>
In reply to#3970
On 11/28/2011 6:26 PM, Doug Miller wrote:
> On 11/28/2011 4:00 PM, Jerry Stuckle wrote:
>> On 11/28/2011 3:42 PM, Doug Miller wrote:
>>> On 11/28/2011 1:57 PM, Jerry Stuckle wrote:
>>>> On 11/28/2011 7:41 AM, Cristiano Larghi wrote:
>>>>> Il Mon, 28 Nov 2011 07:27:16 -0500, Jerry Stuckle ha scritto:
>>>>>
>>>>>> <INPUT id="99_300_prezzo0" name="product_data[0][0][0]"
>>>>>> readOnly="readonly" type="text"> (value for prezzo0)
>>>>>
>>>>> id (and name) *CANNOT* start with a digit ...
>>>>>
>>>>> http://www.w3.org/TR/html4/types.html#type-name
>>>>
>>>> PHP doesn't care...
>>>>
>>> Except to the extent that the HTML error may affect the way the browser
>>> presents the $_POST array to the server. The original post isn't
>>> available to me any more, but IIRC it showed that his $_POST array had
>>> *three* elements where he really wanted only one, e.g.
>>> $_POST ['99']
>>> $_POST ['300']
>>> $_POST ['prezzo0']
>>> where he was expecting to see
>>> $_POST ['99_300_prezzo0']
>>>
>>> ISTM that he may not have had this problem had the HTML code read
>>> <INPUT id="A_99_ ... etc.
>>
>> PHP doesn't care...
>>
> Except to the extent that markup errors [apparently] affect the way the
> $_POST array is presented to the script...

Nope.  An id starting with a numeric doesn't affect how values are posted.

But again, PHP doesn't care.  It uses the information as presented 
(which does NOT include the id= field).  If the HTML is bad, that's not 
a PHP problem.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3963

From"Jesolo Sun" <gala@tiscali.it>
Date2011-11-28 14:31 +0100
Message-ID<4ed38d2b$0$1388$4fafbaef@reader2.news.tin.it>
In reply to#3960

"Jerry Stuckle"  ha scritto nel messaggio news:javunb$78b$1@dont-email.me...

On 11/28/2011 5:33 AM, Jesolo Sun wrote:
> 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').value
> = this.value;cambio_pagamento('99','300');calculate(numero_99_300, 99,
> 300);"
>                                                    class="formfield"
> name="product_data[99][300][numero0]" type="text">

I agree with Erwin that using hidden fields will solve your problem, and
I see no reason they should affect your javascript.  It would require
the least modification to your page.  Using PHP's array functions is
also a solution.

A good start would be to check out foreach(), i.e.

foreach($array = $key=>$value)

You could use this as

foreach ($_POST['product_data'] as $product_id=>$prod_data)
   foreach ($prod_data as $product_variant=>$variant_data)

But I also think your approach can be confusing.  Better I would think
would be to just use product_data[0], product_data[1], etc, with a
hidden field containing id, i.e.

<input type="hidden" name="product_data[0][id]" value="99"> (product id)
<input type="hidden" name="product_data[0][0]" value="300"> (variant)
<INPUT id="99_300_prezzo0"  name="product_data[0][0][0]"
    readOnly="readonly" type="text">  (value for prezzo0)
<INPUT id="99_300_prezzo1"  name="product_data[0][0][1]"
    readOnly="readonly" type="text">  (value for prezzo1)

And so on.



Ok i understand

i have used this example
http://us.php.net/manual/en/function.array-keys.php#73992:

the response of Array is this
Array
(
    [0] => 0
    [1] => product_data
    [2] => 99
    [3] => 300
    [4] => prezzo0
    [5] => prezzo1
    [6] => prezzo2
    [7] => prezzocal0
    [8] => prezzocal1
    [9] => prezzocal2
    [10] => numero0
    [11] => numero1
    [12] => numero2
    [13] => color
    [14] => tipo_stampa
    [15] => il_colore0
    [16] => il_colore1
    [17] => il_colore2
    [18] => ad_adornment
    [19] => 0
    [20] => 1
    [21] => 2
    [22] => 3
    [23] => pacchetto_id
    [24] => colorepack
    [25] => realization_period
    [26] => submit
)

question:
Is it to get this values?

example
$val0 = [2] => 99
$val1 = [4] => 1,44
$val1 = [14] => 2_0



[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.php


csiph-web