2011-11-23 71 views
-1

我試圖用2個表中的數據創建一個循環,這個東西給了我一個錯誤,表示結果不止一行。這是腳本。來自兩個表的sql調用

$query_amoline = "SELECT * FROM `penny_players` WHERE `memid`=\"$curmemid\" AND id= (SELECT id FROM `penny` WHERE `active`='Y') ORDER BY `id` DESC"; 
$amoline = mysql_query($query_amoline) or die(mysql_error()); 
$row_amoline = mysql_fetch_assoc($amoline); 
$totalRows_amoline = mysql_num_rows($amoline); 

<? if($totalRows_amoline>0) 
{ ?> 
<?php do { ?> 
<?php 
$id=$row_amoline['id']; 
$pid=$row_amoline['pennyid']; 

if($totalRows_amoline>0) 
{ ?> 
} 

回答

1

如果

SELECT id FROM `penny` WHERE `active`='Y' 

回報不止一個ID,您的查詢就會失敗。

更改爲:

"SELECT * FROM `penny_players` WHERE `memid`=\"$curmemid\" AND id IN (SELECT id FROM `penny` WHERE `active`='Y') ORDER BY `id` DESC"; 
+0

你們是嚇壞geniusses –

1

你可能是指... AND id IN (...,因爲在penny多行有active設置爲Y

1
"SELECT pp.* 
    FROM penny_players pp 
    WHERE pp.memid=\"$curmemid\" 
     AND EXISTS(SELECT NULL 
         FROM penny p 
         WHERE p.id = pp.id 
          AND p.active = 'Y') 
    ORDER BY pp.id DESC"