Connecting Tech Pros Worldwide Help | Site Map

Optimized or not ?

  #1  
Old July 17th, 2005, 05:58 AM
StinkFinger
Guest
 
Posts: n/a
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
max or not max? Mark answers 1 November 14th, 2006 10:15 PM
Bad? Or not? (But I think I already know...) The Plankmeister answers 72 July 20th, 2005 05:24 PM
To STL or not to STL Allan Bruce answers 41 July 19th, 2005 08:20 PM
to template or not Andrea A answers 16 July 17th, 2005 04:41 AM