Jump to content

PHP loading twice


samja

Recommended Posts

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.

 

???

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

 

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.

 

?

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

 

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.