array inverting itself
am 23.10.2007 22:57:03 von Garry Jones
I have a list of names from some are selected to be displayed on a
form. In this form I create an array of all the displayed values. The
user can select one of them.
Note that only some of the possible names are displayed on the form.
I then want to check that the name the user selects is in the array.
I want to refer to the array on the page the "post" form is pointing
to. So I put the array in a session
$_SESSION['arr_motakt'] = $arr_motakt;
I test here with
print_r (array_values($_SESSION['arr_motakt']));
Which prints my values correctly.
At the top of the page the "post" form points to I have this row again
after starting the session
print_r (array_values($_SESSION['arr_motakt']));
But now it prints an inverted selection of the names, ie the ones that
were not displayed on the form.
Further explanation.
My original list
1 Anna
2 Bertil
3 Conny
4 David
5 Ethel
6 Frank
7 Gertrud
8 Harald
Names displayed on form and shoved into array.
1 Anna
5 Ethel
7 Gertrud
The user can choose 1 or 5 or 7.
When I test the array it prints correctly
1 Anna
5 Ethel
7 Gertrud
The form is posted to the next page.
I test the array on line 2 after starting session and now it says.
2 Bertil
3 Conny
4 David
6 Frank
8 Harald
There is no further code between the form page and the page I post to.
How have I managed to invert the array?
Garry Jones
Sweden
Re: array inverting itself
am 24.10.2007 06:04:57 von zeldorblat
On Oct 23, 4:57 pm, GarryJones wrote:
> I have a list of names from some are selected to be displayed on a
> form. In this form I create an array of all the displayed values. The
> user can select one of them.
>
> Note that only some of the possible names are displayed on the form.
>
> I then want to check that the name the user selects is in the array.
>
> I want to refer to the array on the page the "post" form is pointing
> to. So I put the array in a session
>
> $_SESSION['arr_motakt'] = $arr_motakt;
>
> I test here with
> print_r (array_values($_SESSION['arr_motakt']));
>
> Which prints my values correctly.
>
> At the top of the page the "post" form points to I have this row again
> after starting the session
>
> print_r (array_values($_SESSION['arr_motakt']));
>
> But now it prints an inverted selection of the names, ie the ones that
> were not displayed on the form.
>
> Further explanation.
> My original list
> 1 Anna
> 2 Bertil
> 3 Conny
> 4 David
> 5 Ethel
> 6 Frank
> 7 Gertrud
> 8 Harald
>
> Names displayed on form and shoved into array.
> 1 Anna
> 5 Ethel
> 7 Gertrud
>
> The user can choose 1 or 5 or 7.
>
> When I test the array it prints correctly
> 1 Anna
> 5 Ethel
> 7 Gertrud
>
> The form is posted to the next page.
>
> I test the array on line 2 after starting session and now it says.
>
> 2 Bertil
> 3 Conny
> 4 David
> 6 Frank
> 8 Harald
>
> There is no further code between the form page and the page I post to.
>
> How have I managed to invert the array?
>
> Garry Jones
> Sweden
That seems pretty odd. Can you post all your code so we can take a
look?
Re: array inverting itself
am 24.10.2007 09:04:03 von Garry Jones
> That seems pretty odd. Can you post all your code so we can take a
> look?- Hide quoted text -
Not necessary. I slept on my problem, woke up checked the code,
yippee, I had not started session on the form page and the values
being read in was from an older session on the same site. Thought it
was too odd to be true!