0

I am trying to run another while loop in while loop but only one loop is running, he other is not giving result even when I try to echo the entire sql statement via alert. Can any one help on this?

                                //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;
                        }

                    }

In this entire query the $dim part is not running [code below]. When I try to echo this it shows empty, at least the sql query should have been printed.

               $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'];

                }         
3
  • 2
    please improve on your code indentation, make you code look more pleasing to the eyes so as to make it easier for others to help you. here's a formatting guide: indent code by 4 spaces, replace your tabs with 4 spaces Commented Jan 16, 2012 at 8:12
  • soory for the trouble friend , thanks for looking into the code , glad found a solution later on my self . thanks Commented Jan 16, 2012 at 10:17
  • @Sakshi Please post your solution as answer so that it would be helpful to other folks and mark it as accepted. Hope that helps Commented Jan 17, 2012 at 4:33

1 Answer 1

-1

just use the below query before your first while loop,

$sql1=mysql_query("select * from users_profile where uid=$uid");
1
  • That would not make any difference as long as $uid is an integer. Commented Jan 16, 2012 at 7:20

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.