Connecting Tech Pros Worldwide Help | Site Map

Optimized or not ?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 04:58 AM
StinkFinger
Guest
 
Posts: n/a
Default Optimized or not ?

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.



 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.