Link14716
12-31-2002, 09:19 PM
I created a script to manage cheat codes for my gaming site, but to count the codes per game, it adds a query per game. Example:
--------------------------------------------------------------------------------
Query: SELECT COUNT(*) AS codes FROM post WHERE site='2' && threadid='176'
Time before: 0.32487499713898
Time after: 0.32634603977203
--------------------------------------------------------------------------------
Query: SELECT COUNT(*) AS codes FROM post WHERE site='2' && threadid='177'
Time before: 0.32819998264313
Time after: 0.32953000068665
--------------------------------------------------------------------------------
Query: SELECT COUNT(*) AS codes FROM post WHERE site='2' && threadid='138'
Time before: 0.33139204978943
Time after: 0.3329199552536
--------------------------------------------------------------------------------
Query: SELECT COUNT(*) AS codes FROM post WHERE site='2' && threadid='369'
Time before: 0.33477103710175
Time after: 0.33609294891357
--------------------------------------------------------------------------------
Now, it's not a big deal now, being such a small site, but I wouild like to see how I could optimize the code. Here is the complete action taken from the script:
// START GAME LIST
if ($do=="glist") {
$alphaparent=$DB_site->query_first("SELECT * FROM forum WHERE forumid='$alphaid' ORDER BY displayorder ASC");
$sysname=$DB_site->query_first("SELECT * FROM forum WHERE forumid='$alphaparent[parentid]' ORDER BY displayorder ASC");
$sysname=$sysname[title];
$sysletter=$alphaparent[title];
$typequery=$DB_site->query("SELECT * FROM thread WHERE forumid='$alphaid' ORDER BY title ASC LIMIT 100");
while ($glist=$DB_site->fetch_array($typequery)) {
$gname=$glist[title];
$gid=$glist[threadid];
$countjokes2=$DB_site->query_first("SELECT COUNT(*) AS codes FROM post WHERE site='2' && threadid='$gid'");
$totalgcodes=number_format($countjokes2['codes']);
if ($totalgcodes=="1") {
$c="code";
} else {
$c="codes";
}
eval("\$gbit .= \"".gettemplate("site_v$v" . "_codes_gbits")."\";");
}
eval("dooutput(\"".gettemplate("site_v$v" . "_codes_glistdisplay")."\");");
}
Thanks in advance. :)
--------------------------------------------------------------------------------
Query: SELECT COUNT(*) AS codes FROM post WHERE site='2' && threadid='176'
Time before: 0.32487499713898
Time after: 0.32634603977203
--------------------------------------------------------------------------------
Query: SELECT COUNT(*) AS codes FROM post WHERE site='2' && threadid='177'
Time before: 0.32819998264313
Time after: 0.32953000068665
--------------------------------------------------------------------------------
Query: SELECT COUNT(*) AS codes FROM post WHERE site='2' && threadid='138'
Time before: 0.33139204978943
Time after: 0.3329199552536
--------------------------------------------------------------------------------
Query: SELECT COUNT(*) AS codes FROM post WHERE site='2' && threadid='369'
Time before: 0.33477103710175
Time after: 0.33609294891357
--------------------------------------------------------------------------------
Now, it's not a big deal now, being such a small site, but I wouild like to see how I could optimize the code. Here is the complete action taken from the script:
// START GAME LIST
if ($do=="glist") {
$alphaparent=$DB_site->query_first("SELECT * FROM forum WHERE forumid='$alphaid' ORDER BY displayorder ASC");
$sysname=$DB_site->query_first("SELECT * FROM forum WHERE forumid='$alphaparent[parentid]' ORDER BY displayorder ASC");
$sysname=$sysname[title];
$sysletter=$alphaparent[title];
$typequery=$DB_site->query("SELECT * FROM thread WHERE forumid='$alphaid' ORDER BY title ASC LIMIT 100");
while ($glist=$DB_site->fetch_array($typequery)) {
$gname=$glist[title];
$gid=$glist[threadid];
$countjokes2=$DB_site->query_first("SELECT COUNT(*) AS codes FROM post WHERE site='2' && threadid='$gid'");
$totalgcodes=number_format($countjokes2['codes']);
if ($totalgcodes=="1") {
$c="code";
} else {
$c="codes";
}
eval("\$gbit .= \"".gettemplate("site_v$v" . "_codes_gbits")."\";");
}
eval("dooutput(\"".gettemplate("site_v$v" . "_codes_glistdisplay")."\");");
}
Thanks in advance. :)