Second while loop not running. Why?

后端 未结 6 1849
没有蜡笔的小新
没有蜡笔的小新 2021-01-15 11:37

I have two while loops running one after the other (not inside of each other) - I\'ve simplified the code a bit so that only the important parts of it are listed below. The

6条回答
  •  孤城傲影
    2021-01-15 11:42

    According to your posted code, your SQL will look something like:

    SELECT title FROM works WHERE OR '1'

    That query will result in an error so your script shouldn't be getting past that point.

    Even if it does, your second loop:

    while ($row = mysql_fetch_assoc($result_work_id))

    is using a result handle that has already been completely iterated by the first loop. By the the time the second loop tries to use it, mysql_fetch_assoc will return FALSE because there are no more rows to fetch. This will cause the second loop to exit immediately.

    If both while loops need to access the same rows, combine their logic so the rows only need to be iterated over one time.

提交回复
热议问题