所以基本上,我有一个排名脚本,它很好用。
我只显示登录帐户中的字符。
这意味着WHERE account.id = $ userid,我已经了解了这一部分。
我的问题是mysqli查询的外观如何?
我尝试将WHERE account.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
,这将导致查询不返回任何结果。