0

I'm running one while inside another while but the second one is running only one time why and how can I fix it. I have also try with for but running again only once.

$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';
    }
}
3
  • you should really place your mysql_fetch_assoc outside of the condition to improve performance as each time it loops, mysql_fetch_assoc is being evaluate every times. but i'm sure that's not the real problem though. Commented Sep 23, 2015 at 18:29
  • Do you have more than one row which matching $results. check number of rows of $results also. Note: Now its time to go to mysqli @lmBigNoob Commented Sep 23, 2015 at 18:43
  • what's the value of $episodes? Commented Sep 23, 2015 at 18:51

1 Answer 1

3

You are overriding the variables, use different ones:

$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';
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

No thats not the proble take a look better I dont ovverriding the variables

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.