sql 活出另一个表中的项目

发布于 2024-09-30 09:03:20 字数 937 浏览 3 评论 0原文

我正在整理一个联赛剧本。当有人注册联赛时,他们会从下拉字段中的可用球队列表中进行选择。

我遇到的问题是,当有多个字段时,我会收到此错误消息。

“子查询返回超过 1 行”的

脚本如下:

//List available teams
$query_chamoline = "SELECT * FROM MLB WHERE `team`<>(SELECT `team` FROM leaguemembers     WHERE `leagueid`=\"$lid\" AND `active`='Y') ORDER BY `team` ASC";
$chamoline = mysql_query($query_chamoline) or die(mysql_error());
$row_chamoline = mysql_fetch_assoc($chamoline);
$totalRows_chamoline = mysql_num_rows($chamoline);

<select id="team">
<option value="">Select Available Team</option>
<?php do { ?>   

  <?php
$tname=$row_chamoline['team'];

if($totalRows_chamoline>0)
{?>
<option value="<?php echo $tname ?>"><?php echo $tname ?></option><?php }} while     ($row_chamoline = mysql_fetch_assoc($chamoline)); ?>
</select>

我从 MLB 表中的球队总列表中进行选择,该列表与 leaguemembers 表中其他成员选择的球队不匹配。

I'm putting together a league script. When someone registers for a league they choose from a list of available teams in a drop down field.

The problem i'm having is that I'm getting this error message when there are more than one fields.

"Subquery returns more than 1 row"

here's the script:

//List available teams
$query_chamoline = "SELECT * FROM MLB WHERE `team`<>(SELECT `team` FROM leaguemembers     WHERE `leagueid`=\"$lid\" AND `active`='Y') ORDER BY `team` ASC";
$chamoline = mysql_query($query_chamoline) or die(mysql_error());
$row_chamoline = mysql_fetch_assoc($chamoline);
$totalRows_chamoline = mysql_num_rows($chamoline);

<select id="team">
<option value="">Select Available Team</option>
<?php do { ?>   

  <?php
$tname=$row_chamoline['team'];

if($totalRows_chamoline>0)
{?>
<option value="<?php echo $tname ?>"><?php echo $tname ?></option><?php }} while     ($row_chamoline = mysql_fetch_assoc($chamoline)); ?>
</select>

I'm selecting from the total list of teams in the MLB table that doesn't match the teams picked by other members in the leaguemembers table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜尕妞 2024-10-07 09:03:20

更改“<>”与“不在(...)”

为什么? “<>”除了单个值(例如 'team' <> 'xxx'),“not in” 使用一组逻辑来处理许多项目(例如 'team' not in ('aaa','bbb','ccc '))

change "<>" with "not in (...)"

why? "<>" excepts a single value (ex. 'team' <> 'xxx'), "not in" uses a set logic to handle many items (ex. 'team' not in ('aaa','bbb','ccc'))

内心旳酸楚 2024-10-07 09:03:20

尝试使用 NOT IN 代替:

$query_chamoline = "SELECT * FROM MLB WHERE `team` NOT IN(SELECT `team` FROM leaguemembers     WHERE `leagueid`=\"$lid\" AND `active`='Y') ORDER BY `team` ASC";

Try using NOT IN instead:

$query_chamoline = "SELECT * FROM MLB WHERE `team` NOT IN(SELECT `team` FROM leaguemembers     WHERE `leagueid`=\"$lid\" AND `active`='Y') ORDER BY `team` ASC";
白鸥掠海 2024-10-07 09:03:20

此更改将停止错误,但不会停止逻辑错误(如果存在)

$query_chamoline = "SELECT * FROM MLB WHERE `team`<>(SELECT TOP 1 `team` FROM leaguemembers     WHERE `leagueid`=\"$lid\" AND `active`='Y') ORDER BY `team` ASC";

查看他的答案我希望 Ass3mbler 是正确的。

This change will stop the error, but not the logic error (if it exists)

$query_chamoline = "SELECT * FROM MLB WHERE `team`<>(SELECT TOP 1 `team` FROM leaguemembers     WHERE `leagueid`=\"$lid\" AND `active`='Y') ORDER BY `team` ASC";

looking at his answer I expect Ass3mbler is right.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文