Jump to content

PHP loading twice


samja

Recommended Posts

 

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
https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698792
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
https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698805
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
https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698840
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
https://forums.phpfreaks.com/topic/134238-php-loading-twice/#findComment-698886
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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