samja Posted November 25, 2008 Share Posted November 25, 2008 What can be the reason when my index-page is loaded twice? Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/ Share on other sites More sharing options...
flyhoney Posted November 25, 2008 Share Posted November 25, 2008 Post some code or we can't really help you Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698786 Share on other sites More sharing options...
samja Posted November 25, 2008 Author Share Posted November 25, 2008 in index.php: include('code/incs.php'); include('main.php'); then after call of $var = func() (in incs.php) from main.php causes all loading twice. if func() returns simple number like 5, all works. But if it returns an array, the code is run again. ??? Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698788 Share on other sites More sharing options...
Maq Posted November 25, 2008 Share Posted November 25, 2008 Please post ALL the code. Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698789 Share on other sites More sharing options...
samja Posted November 25, 2008 Author Share Posted November 25, 2008 index.php: include('code/incs.php'); include('code/main.php'); code/incs.php: function getRec($taulu, $kentat, $lopuke = '') { $qstr = "SELECT $kentat FROM $taulu $lopuke"; $qres = mysql_query($qstr); if ($qres === false) return false; $t = mysql_fetch_array($qres, MYSQL_ASSOC); mysql_free_result($qres); return $t; } function func() { global $arr; $arr = getRec('versiot', '*', "WHERE active=1"); } } code/main.php: func(); if in function func() i comment the global line, the code is not loaded twice. Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698792 Share on other sites More sharing options...
samja Posted November 25, 2008 Author Share Posted November 25, 2008 if from getRec I return a record from database, Array ( [id] => 32 [sitename] => sp1 [logo] => [valikot] => valikot_sp1 [active] => 0 [onwork] => 1 [teema] => perus [naytalogo] => 0 [naytasitename] => 0 [kanta] => sp1 ) then all are loaded twice. If I return an array: array(1,2,3), that does not happen. ? Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698805 Share on other sites More sharing options...
samja Posted November 25, 2008 Author Share Posted November 25, 2008 This is very annoying, since all tables in sql-database can be renamed silly when names are constructed with emtpy $_POST variable (on second run). Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698810 Share on other sites More sharing options...
samja Posted November 25, 2008 Author Share Posted November 25, 2008 Srange: If I use MYSQL_NUM insted of MSQL_ASSOC, all works properly. Nothing is loaded again. function getRec($taulu, $kentat, $lopuke = '') { $qstr = "SELECT $kentat FROM $taulu $lopuke"; $qres = mysql_query($qstr); if ($qres === false) return false; $t = mysql_fetch_array($qres, MYSQL_NUM); mysql_free_result($qres); return $t; } Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698840 Share on other sites More sharing options...
samja Posted November 25, 2008 Author Share Posted November 25, 2008 Yess. All works fine. This goes over my level to understand. Thanks for listening! Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698878 Share on other sites More sharing options...
Maq Posted November 25, 2008 Share Posted November 25, 2008 Srange: If I use MYSQL_NUM insted of MSQL_ASSOC, all works properly. Nothing is loaded again. function getRec($taulu, $kentat, $lopuke = '') { $qstr = "SELECT $kentat FROM $taulu $lopuke"; $qres = mysql_query($qstr); if ($qres === false) return false; $t = mysql_fetch_array($qres, MYSQL_NUM); mysql_free_result($qres); return $t; } MSQL_ASSOC? Do you mean MYSQL_ASSOC? I don't even see where you use this in the first place... Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698886 Share on other sites More sharing options...
samja Posted November 25, 2008 Author Share Posted November 25, 2008 MSQL_ASSOC? Do you mean MYSQL_ASSOC? I don't even see where you use this in the first place... Sorry, I wrote it wrong. Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698928 Share on other sites More sharing options...
iversonm Posted November 25, 2008 Share Posted November 25, 2008 just change all your includes or requires to require_once() and nothing will be repeated Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698942 Share on other sites More sharing options...
samja Posted November 26, 2008 Author Share Posted November 26, 2008 just change all your includes or requires to require_once() and nothing will be repeated But the whole index-file also gets loaded twice. Not only the included files. I cut some code and that fixed the problem. There might be a bug in PHP somewhere? Quote Link to comment https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-699152 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.