gpt4 book ai didi

php - 如何仅显示与另一个表中的值匹配的行

转载 作者:行者123 更新时间:2023-11-28 23:32:57 25 4
gpt4 key购买 nike

在这样的情况下它会如何工作?我什至尝试过使用“AND tb1.name !=”,但没有用。

$area = 0;
$stmt = $dbh->prepare('SELECT * FROM charinfo WHERE current_area != :area ORDER BY current_area');
$stmt->execute(array('area' => $area));
$result = $stmt->fetchAll();
$place = 1;

我运行一个游戏服务器,在网站上我有一个前 30 名的排行榜,它正在创造奇迹(直接从另一个主题中找到代码),我遇到的问题是无法使用 JOIN 函数每个人都在建议,以防止管理员的字符也被列出。

这是我现在网站上的代码,它在表格中显示了等级编号 1-30、角色名称和级别。 Here's it working on my website

<?php
require("srvcs/config.php");
$stmt = $dbh->prepare('SELECT * FROM chars ORDER BY CAST(experience AS UNSIGNED ) DESC LIMIT 30;');
$stmt->execute();
$result = $stmt->fetchAll();
$place = 1;

echo '<table class="justShowme" style="width:600px;height:150px;">

<tr>
<td>Rank</td>
<td>Character Name</td>
<td>Level</td>
</tr>';

foreach ($result as $index => &$item) {

$exp = floor(pow($item['experience'] + 1, 1/4));
$name = $item['name'];

echo '<tr>';
echo "<td><B>" . $place++ . "</B></td>";
echo "<td>" . $name . "</td>";
echo "<td>" . $exp . "</td>";
echo '</tr>';
}
echo '</table></center>';
?>

我对 MySQL 不是很熟悉,所以我将首先列出我所知道的必要内容...

  1. 'chars'表包含字符信息

    'sID' column is unique and matches the subscriber 'ID' column, whoever owns the character
  2. 'subscriber' 表包括帐户信息和管理员状态

    'ID' is the subscriber ID which the 'sID' from chars table refers to
    'admin' is the admin status of the account as Y or N

如果角色的订阅者 ID 的 sID 值为 admin 值为 Y,则不应列出。

如果角色的sID值为admin值N的订阅者ID,则将被列出,表格以DESC形式列出,只显示30行结果。

我该怎么做?

任何帮助将不胜感激!这是我的第一篇文章,所以关于 future 帮助请求的提示也很好 :) 在此先感谢您!

最佳答案

SELECT tb1.*
FROM chars tb1
JOIN subscriber tb2
ON tb1.sID=tb2.ID
WHERE admin = 'N'
ORDER BY CAST(experience AS UNSIGNED ) DESC
LIMIT 30;

关于php - 如何仅显示与另一个表中的值匹配的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36856618/

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