2012-01-16 17 views
0

whileループ中に別のループを実行しようとしていますが、ループが1つしか実行されていません。誰にでもこれを助けることができますか?whileループ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']; 

       }   
+0

があるuidは整数である、あなたの最初のwhileループの前に以下のクエリを使用できますか? –

+2

あなたのコードの字下げを改善してください。他の人があなたを助けやすくするために、コードを目で見やすくするようにしてください。ここに書式設定のガイドがあります: 'インデントコードを4スペースで'、 'タブを' 4スペースに置き換えてください – ianace

+0

問題の友達のために、コードを調べてくれてありがとう。ありがとう –

答えて

-1

はちょうど

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

'$ uid'が整数である限り、それは何の違いもありません。 – Eric

関連する問題