开发者

sql live out items from another table

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 valu开发者_JS百科e="">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.


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'))


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";


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜