php - 如何让前五个计算只出现
问题描述
我有一个狗展网站,并试图展示在一年中获得最多分数的前五个犬舍词缀。
我已经拆分了代码中的观点,并在两个表上使用了内部连接。一个是结果和其他狗
我在显示词缀名称及其旁边获得的分数时遇到问题。也无法根据最多积分获得前五名
警告:在第 59 行的 xxx 中遇到一个非数字值
注意:未定义的变量:第 68 行的 xxx 中的总数
下面是所有显示的内容,我认为它正在添加 if 语句。
3
6
对不起,不是很擅长,需要一些帮助。
<?php
$query = "SELECT result.placement, result.award, result.class_name, dogs.affix
FROM result
INNER JOIN dogs
ON result.resultID = dogs.dog_id
ORDER BY dogs.affix LIMIT 5";
$result = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($result)){
$affix = $row['affix'];
$placement = $row['placement'];
$award = $row['award'];
if($award === 'BCC'){
$points = $affix + 5;
}
if($award === 'DCC'){
$points = $affix + 5;
}
if($award === 'RBCC'){
$points = $affix + 4;
}
if($award === 'RDCC'){
$points = $affix + 4;
}
if($placement === '1st'){
$points = $affix + 3;
}
if($placement === '2nd'){
$points = $affix + 2;
}
if($placement === '3rd'){
$points = $affix + 1;
}
$total += $points;
echo "<li> {$affix} {$total}</li>";
}
?>
解决方案
三个问题。
ORDER BY dogs.affix LIMIT 5
返回底部5 而不是顶部。应该是ORDER BY dogs.affix DESC LIMIT 5
登顶。affix
返回一个null
或一个空字符串,这就是你得到第一个错误的原因。int not null default 0
在您的数据库中定义此字段。- $total 未初始化。在循环之前将其赋值为 0
推荐阅读
- python - 按下按钮Pyqt5后从QtextEdit中删除文本
- node.js - nodejs 与后端连接的库
- python - 使用 API Python 显示来自surveygizmo 调查的问题
- python - PyQT5 更改任务栏图标
- reactjs - 为什么 GitHub Pages 不显示我的 React Redux Todo Web 应用程序
- java - 如何列出二进制数java
- reactjs - 如何从反应打字稿前端读取 application.yml 文件
- reactjs - 类型“typeof class”不可分配给类型“ComponentType”
' - ios - 在 SwiftUI 中观察系统体积
- javascript - 我在 .live() 中遇到问题不是函数