Skip to content

Commit

Permalink
Use bind parameters in dbTagList query, remove loop
Browse files Browse the repository at this point in the history
  • Loading branch information
salty-horse committed Dec 10, 2024
1 parent 311ac80 commit b9528c5
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions www/viewgame
Original file line number Diff line number Diff line change
Expand Up @@ -2731,32 +2731,28 @@ if ($embargoCnt > 0)
<script type="module" nonce="<?php global $nonce; echo $nonce; ?>">
import {initTagTable} from './viewgame.js';

var dbTagList = [
<?php
$isMine = ($curuser
? "sum(userid = '$curuser' and gameid = '$qid')"
: "0");
$result = mysql_query(
var dbTagList = <?php
if ($curuser) {
$isMine = "cast(sum(userid = ? and gameid = ?) as int)";
$isMineParams = [$curuser, $id];
} else {
$isMine = "0";
$isMineParams = [];
}
$result = mysqli_execute_query($db,
"select
tag,
sum(gameid = '$qid') as tagcnt,
cast(sum(gameid = ?) as int) as tagcnt,
count(distinct gameid) as gamecnt,
$isMine as isMine
from gametags
where tag in (select tag from gametags where gameid = '$qid')
where tag in (select tag from gametags where gameid = ?)
group by tag
order by tag", $db);
$cnt = mysql_num_rows($result);

for ($i = 0 ; $i < $cnt ; $i++) {
list($tag, $tagcnt, $gamecnt, $isMine) = mysql_fetch_row($result);
$tag = jsSpecialChars($tag);
echo ($i > 0 ? "," : "")
. "{tag: \"$tag\", tagcnt: $tagcnt, "
. "gamecnt: $gamecnt, isMine: $isMine}";
}
order by tag", [$id, ...$isMineParams, $id]);

echo json_encode(mysqli_fetch_all($result, MYSQLI_ASSOC));
?>
];
;

initTagTable("<?php echo $id ?>", dbTagList, <?php echo $adminPriv ?>);
//-->
Expand Down

0 comments on commit b9528c5

Please sign in to comment.