Perad Posted November 22, 2007 Share Posted November 22, 2007 I have 2 arrays... one works and one doesn't. The first one brings about this error. Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 35 bytes) in /Applications/xampp/xamppfiles/htdocs/minisite/scripts/user_cp/register.php on line 145 $sql = "SELECT * FROM ucp_fields"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $upcf_data[] = array("ucpf_name" => $row['ucpf_name'], "ucpf_compulsory" => $row['ucpf_compulsory'] ); } This one has no error. From what I can tell they are both identical... $sql = "SELECT * FROM ucp_fields"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { if ($row['ucpf_compulsory'] == 1) { $ucp_forms_compulsory[] = array( "ucpf_name" => $row['ucpf_name'], "ucpf_maxlength" => $row['ucpf_maxlength'], "ucpf_type" => $row['ucpf_type'], "ucpf_register_values" => $row['ucpf_register_values'] ); } } Help finding what is causing this would be very very welcome Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 22, 2007 Share Posted November 22, 2007 they are not identical you have a if condition in the second code (which does not cause the error) if ($row['ucpf_compulsory'] == 1) { this might filter out a lot of rows causing the array to be smaller Quote Link to comment Share on other sites More sharing options...
Perad Posted November 22, 2007 Author Share Posted November 22, 2007 The table has only got 7 rows.. If I replace the array with print 1; Seven 1's are printed. However with the array it just freezes. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 22, 2007 Share Posted November 22, 2007 can you post your code which is causing the errors its hard too tell your syntax looks good and identical and if you just have 7 rows there should not be any problem Quote Link to comment Share on other sites More sharing options...
Perad Posted November 22, 2007 Author Share Posted November 22, 2007 Error line is 145 and line 145 is the line starting $upcf_data shown below. $upcf_data[] = array( "ucpf_name" => $row['ucpf_name'], "ucpf_compulsory" => $row['ucpf_compulsory'] ); Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 22, 2007 Share Posted November 22, 2007 well its hard to tell just with that one line maybe your $upcf_data is already has some data in it I always would do $sql = "SELECT * FROM ucp_fields"; $result = mysql_query($sql); $upcf_data = array(); while ($row = mysql_fetch_assoc($result)) { $upcf_data[] = array("ucpf_name" => $row['ucpf_name'], "ucpf_compulsory" => $row['ucpf_compulsory'] ); } before using any array in my code Quote Link to comment Share on other sites More sharing options...
Perad Posted November 22, 2007 Author Share Posted November 22, 2007 That doesn't work.. On closer inspection... $upcf_data[] = array( "ucpf_compulsory" => $row['ucpf_compulsory'] ); Doesn't work. This does $upcf_data[] = array( "ucpf_name" => $row['ucpf_name'] ); However the code below works fine. print $row['ucpf_compulsory']; Quote Link to comment Share on other sites More sharing options...
Perad Posted November 22, 2007 Author Share Posted November 22, 2007 Could it be that the array contains value contains numbers? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 22, 2007 Share Posted November 22, 2007 this is very strange it should work without any problem maybe other gurus on the site could help although am looking into the code why don't you just try printing echo $row['ucpf_compulsory']; instead of the print 1 maybe there some problem with the fetching Quote Link to comment Share on other sites More sharing options...
Perad Posted November 22, 2007 Author Share Posted November 22, 2007 It echo's fine. It's weird, its like the array is creating a look to infinity.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.