sql 活出另一个表中的项目
我正在整理一个联赛剧本。当有人注册联赛时,他们会从下拉字段中的可用球队列表中进行选择。
我遇到的问题是,当有多个字段时,我会收到此错误消息。
“子查询返回超过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更改“<>”与“不在(...)”
为什么? “<>”除了单个值(例如 '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'))
尝试使用 NOT IN 代替:
Try using NOT IN instead:
此更改将停止错误,但不会停止逻辑错误(如果存在)
查看他的答案我希望 Ass3mbler 是正确的。
This change will stop the error, but not the logic error (if it exists)
looking at his answer I expect Ass3mbler is right.