mysql_fetch_array() 函数从结果集中取得一行作为关联数组,或数字数组,或二者兼有
返回根据从结果集取得的行生成的数组,如果没有更多行则返回 false。
可是重新进入第二个while不是会重新执行mysql_fetch_array() 吗?

解决方案 »

  1.   

    二重循环的算法时间复杂度为 O(n*n) 
    即内层循环体将执行 n(外层)* n(内层)次不过你的嵌套循环是多余的,因为你都是对同一资源($_show_repost)进行循环
    所以外层会执行一次,内层会执行n-1次
      

  2.   

    while(!!$_rerows = mysql_fetch_array($_show_repost,MYSQL_ASSOC)){         循环语句1          while(!!$_rerows = mysql_fetch_array($_show_rerepost,MYSQL_ASSOC)){
                             循环语句2
               }
    }不好意思各位楼上代码写错了,是查询2个不同的
      

  3.   

    那么内层的 $_show_rerepost 需要重新查询或回绕
      

  4.   

    表一 回帖信息
    表二 回帖的回复
    所以表二中必有一字段指向表一的id,假设为 fid
    于是有$_show_repost = mysql_query('select * from 表一');
    where($_rerows = mysql_fetch_array($_show_repost,MYSQL_ASSOC)) {
      $_show_rerepost = mysql_query("select * from 表二 where 表二.fid=$_rerows[id]");
      while(!!$_rerows = mysql_fetch_array($_show_rerepost,MYSQL_ASSOC)){
      }
    }