2015-09-23 178 views
0

我在另一個內部運行一個,但第二個只運行一次爲什麼以及如何修復它。我也嘗試過,但只能再次運行一次。PHP - Loop內部循環第二個循環只運行一次

$sql = "SELECT DISTINCT season FROM search WHERE link = '$getid' Order by id asc"; 
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); 
while ($list = mysql_fetch_assoc($result)) 
{ 
    $season = $list['season']; 
    $sql = mysql_query("SELECT * FROM search WHERE link = '$getid' and season = '$season'"); 
    $episodes = mysql_num_rows($sql); 
    echo '1st'; 
    $sqls = "SELECT * FROM search WHERE link = '$getid' and season = '$season' Order by id asc"; 
    $results = mysql_query($sqls, $conn) or trigger_error("SQL", E_USER_ERROR); 
    while ($lists = mysql_fetch_assoc($results)) 
    { 
     $episode = $lists['episode']; 
     echo'2nd'; 
    } 
} 
+0

你應該把你的mysql_fetch_assoc的條件之外,以提高性能爲每次循環,mysql_fetch_assoc正在每次評估的時間。但我確定這不是真正的問題。 – cylua2

+0

您是否有多個匹配$結果的行。還要檢查$結果的行數。 注意:現在它的時間去mysqli @lmBigNoob –

+0

$集的價值是什麼? – Engin

回答

3

要覆蓋變量,使用不同的:

$sql = "SELECT DISTINCT season FROM search WHERE link = '$getid' Order by id asc"; 
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); 
while ($list = mysql_fetch_assoc($result)) 
{ 
    $season = $list['season']; 
    $sql2 = mysql_query("SELECT * FROM search WHERE link = '$getid' and season = '$season'"); 
    $episodes = mysql_num_rows($sql2); 
    echo '1st'; 
    $sqls = "SELECT * FROM search WHERE link = '$getid' and season = '$season' Order by id asc"; 
    $results2 = mysql_query($sqls, $conn) or trigger_error("SQL", E_USER_ERROR); 
    while ($lists2 = mysql_fetch_assoc($results2)) 
    { 
     $episode = $list2['episode']; 
     echo'2nd'; 
    } 
} 
+0

這不是問題看起來更好看我不包括變量 – ImBigNoob