Connecting Tech Pros Worldwide Forums | Help | Site Map

Optimized or not ?

StinkFinger
Guest
 
Posts: n/a
#1: Jul 17 '05
All,
Been reading other posts on other forums, i.e. Nukecops.

My original code is this:

function is_active($module) {
global $prefix, $dbi;
$result = sql_query("select active from web_modules where
title='$module'", $dbi);
list ($act) = sql_fetch_row($result, $dbi);
if (!$result OR $act == 0) {
return 0;
} else {
return 1;
}
}

I changed it to this:
function is_active($module) {
global $dbi;
static $save;
if (is_array($save)) {
if (isset($save[$module])) return ($save[$module]);
return 0;
}
$result = sql_query("select active from web_modules where
title='$module'", $dbi);
while ($act = sql_fetch_row($result, $dbi)) {
$save[$act[0]] = 1;
}
if (isset($save[$module])) return ($save[$module]);
return 0;
}

Is the changed version "optimized", meaning that it doesn't perform the
query if it doesn't need to ?
Thanks.



Closed Thread