By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

Optimized or not ?

P: 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.
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.