在while循环下使用while时,sql查询未运行


sql query not running when using while under while loop

我正试图在while循环中运行另一个while循环,但只有一个循环在运行,即使我试图通过警报回显整个sql语句,另一个也没有给出结果。有人能帮上忙吗?

                                //Insert Comments
                    public function Insert_Comment($uid,$msg_id,$comment,$ip,$cfid) 
                    {
                    $comment=mysql_real_escape_string($comment);
                            $time=time();
                       $ip=$_SERVER['REMOTE_ADDR'];
                        $query = mysql_query("SELECT com_id,comment FROM `comments` WHERE uid_fk='$uid' and msg_id_fk='$msg_id' order by com_id desc limit 1 ") or die(mysql_error());
                        $result = mysql_fetch_array($query);
                        if ($comment!=$result['comment']) {
                        $query = mysql_query("INSERT INTO `comments` (comment, uid_fk,msg_id_fk,ip,created,cfid) VALUES (N'$comment', '$uid','$msg_id', '$ip','$time','$cfid')") or die(mysql_error());

                 $sql1=mysql_query("select * from users_profile where uid='$uid'");
                 while($row1=mysql_fetch_array($sql1))
                    {
                     $reqfname=$row1['fname'];
                     $reqpic=$row1['profile_pic'];
                     $reqsex=$row1['sex'];
                     $requid=$row1['uid'];
                     $notify = mysql_query("insert into notification(notification_id,type_id,item_id,user_id,owner_user_id,is_seen,time_stamp,title_html,title_text,body_html,body_text,href,icon_url)values('','wall_comments','4','$cfid','$uid','0',now(),'<b> Global Notification</b>','Global Notification','<img alt=notification icon src=$reqpic></span><span class=message>$reqfname shared view on your Status Update</span><span class=close></span>','$reqfname shared view on your Status Update','demo','')");
                $dim=mysql_query("SELECT m.msg_id,m.uid_fk,c.com_id,c.msg_id_fk,c.uid_fk,c.cfid,n.type_id,n.user_id,n.owner_user_id,n.href,n.time_stamp from messages m ,comments c, notification n where m.msg_id=c.msg_id_fk and m.uid_fk=c.uid_fk and c.uid_fk=n.owner_user_id and c.cfid=n.user_id and n.type_id='wall_comments' and  c.uid_fk=$uid and c.cfid=$cfid and n.href='$href' order by n.time_stamp desc");
                 while($rom=mysql_fetch_array($dim))
                    {
                    echo "SELECT m.msg_id,m.uid_fk,c.com_id,c.msg_id_fk,c.uid_fk,c.cfid,n.type_id,n.user_id,n.owner_user_id,n.href,n.time_stamp from messages m ,comments c, notification n where m.msg_id=c.msg_id_fk and m.uid_fk=c.uid_fk and c.uid_fk=n.owner_user_id and c.cfid=n.user_id and n.type_id='wall_comments' and  c.uid_fk=$uid and c.cfid=$cfid and n.href='$href' order by n.time_stamp desc";
                echo "man";
                     $oldhref=$rom['href'];
                }         
                          $newquery = mysql_query("SELECT C.com_id, C.uid_fk, C.comment, C.msg_id_fk, C.created, U.username FROM comments C, users U where C.uid_fk=U.uid and C.uid_fk='$uid' and C.msg_id_fk='$msg_id' order by C.com_id desc limit 1 ");
                            $result = mysql_fetch_array($newquery);
                           return $result;
                           }
                        } 
                        else
                        {
                        return false;
                        }
                    }

在整个查询中,$dim部分没有运行[下面的代码]。当我尝试回显它时,它显示为空,至少sql查询应该已经打印出来了。

               $dim=mysql_query("SELECT m.msg_id,m.uid_fk,c.com_id,c.msg_id_fk,c.uid_fk,c.cfid,n.type_id,n.user_id,n.owner_user_id,n.href,n.time_stamp from messages m ,comments c, notification n where m.msg_id=c.msg_id_fk and m.uid_fk=c.uid_fk and c.uid_fk=n.owner_user_id and c.cfid=n.user_id and n.type_id='wall_comments' and  c.uid_fk=$uid and c.cfid=$cfid and n.href='$href' order by n.time_stamp desc");
                 while($rom=mysql_fetch_array($dim))
                    {
                    echo "SELECT m.msg_id,m.uid_fk,c.com_id,c.msg_id_fk,c.uid_fk,c.cfid,n.type_id,n.user_id,n.owner_user_id,n.href,n.time_stamp from messages m ,comments c, notification n where m.msg_id=c.msg_id_fk and m.uid_fk=c.uid_fk and c.uid_fk=n.owner_user_id and c.cfid=n.user_id and n.type_id='wall_comments' and  c.uid_fk=$uid and c.cfid=$cfid and n.href='$href' order by n.time_stamp desc";
                echo "man";
                     $oldhref=$rom['href'];
                }         

只需在第一个while循环之前使用以下查询

$sql1=mysql_query("select * from users_profile where uid=$uid");