|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-09-01 17:47 UTC] joshua dot montgomery at middlebrow dot com
Description:
------------
We fixed this bug by setting Register_Globals to "Off", but we were also making other changes on the server to solve it, so that might not have been the fix.
We are using the following code to store database entries in memory for use later on in the page
When allocating memory for an array dynamically using a sql_query the values came out as strings, rather than arrays.
I took all of the error checking out of the code below to make it more clear. We use this code to dump an array to a select menu creation function.
It should be noted that this bug doesn't always appear, but seems to be produced for larger arrays (10 - 25) rather than arrays containing 2 or 3 entries.
It should also be noted that adding the statement "$ArrayVariable = array()" before the following code also solves the problem.
Reproduce code:
---------------
$rslt = mysql_query("SQL....")
$i = 0;
while ($row = mysql_fetch_array($rslt)) {
$ArrayVariable[$i]['Value'] = $row['SQL_Text Value'];
$ArrayVariable[$i]['Label'] = $row['SQL_Text Label'];
$i++;
}
print_r($ArrayVariable);
Expected result:
----------------
Array
(
[0] => Array
(
[Value] => 145
[Label] => Adair, Kris
)
[1] => Array
(
[Value] => 20
[Label] => Bailey, Wayne
)
[2] => Array
(
[Value] => 22
[Label] => Bartos, Alan
)
[3] => Array
(
[Value] => 24
[Label] => Beatty, Marsha
)
)
Actual result:
--------------
Array
(
[0] => 1A
[1] => 2B
[2] => 2B
[3] => 2B
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 18:00:01 2025 UTC |
Try to you unset $ArrayVariable's value before while{} - I bet you'll get the expected result. This happens because with register_globals=On $ArrayVariable gets extracted from SESSION, GET, POST or from other sources. Please supply _working, complete_ reproduce script next time.