Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bind parameters in dbTagList query, remove loop #1205

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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