gpt4 book ai didi

php - MySQLi 排名脚本

转载 作者:行者123 更新时间:2023-11-29 12:41:33 25 4
gpt4 key购买 nike

基本上,我有一个排名脚本,效果很好。我让它只显示登录帐户中的字符。这意味着 WHERE accounts.id=$userid,我已经涵盖了该部分。

我的问题是 mysqli 查询应该是什么样子?我尝试将 WHERE accounts.id=".$userid."我收到非对象错误,我认为这意味着我的 $sql 搞砸了。

您可以忽略缺少的表顶部部分和 $jobs 变量,它不相关。

<?php
if (isset($_GET['start'])) {
if ($_GET['start'] >= 0 && $_GET['start'] <= 1000) {
$start = sql_injectionproof($_GET['start']);
} else {
die("Input not allowed.");
}
} else {
$start = 0;
}
$mysqli = new mysqli("XXXXXX", "XXXXX", "XXXXXXXX", "XXXXXXX");
$i = $start;
$sql = $mysqli->query("SELECT characters.name , characters.job, characters.level, characters.experience, characters.fame, accounts.isloggedin FROM characters, accounts WHERE accounts.username=".$username." and characters.accountid=accounts.id and characters.ismaster = 0 and accounts.isbanned = 0 ORDER BY characters.level DESC, characters.experience DESC LIMIT ".sql_injectionproof($start).", 500");
while ($outcome = $sql->fetch_array()) { ?>

<tr>
<td class="center" style="vertical-align: middle;">#<?php echo"".++$i.""; ?></td>
<td class="center" style="vertical-align: middle;"><img src="images/char/create.php?name=<?php echo "".$outcome['name'].""; ?>" alt="<?php echo $outcome['name']; ?>"></td>
<td class="center" style="vertical-align: middle;"><?php echo "".$outcome['name'].""; ?></td>
<td class="center" style="vertical-align: middle;"><?php echo "".$outcome['level'].""; ?></td>
<td class="center" style="vertical-align: middle;"><?php echo "".$jobs[$outcome['job']].""; ?></td>
</tr>

<?php
}
if ($start >= 0 && $start <= 1000) {
$nextstart = $start + 10;
if ($start >= 2) {
$prevstart = $start - 10;
} else {
$prevstart = 0;
}
} else if ($start > 180 && $start <= 1000) {
$prevstart = $start - 2;
$nextstart = 1000;
} else {
die("Hacks.");
}
?>

最佳答案

您的字符串值缺少引号:

WHERE accounts.username=".$username." and 

应该是:

WHERE accounts.username='".$username."' and 

此外,$username 似乎未定义,这将导致您的查询不返回任何结果。

关于php - MySQLi 排名脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26050219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com