在显示结果之前查询运行

时间:2013-12-03 21:37:43

标签: php mysql execution

我有代码,它显示已记录用户的未读消息,并在代码的末尾验证消息以将其标记为已读,但查询在所有内容之前运行并且不显示该查询的未读消息并执行全部在显示之前读取。怎么解决这个?

<?php
    $query= mysql_query("SELECT 
                R.id_reply,R.visto,R.visto2,R.timeago,R.cr_id,R.time,R.reply,
                U.id,U.username,U.user_mail,C.user_one,C.user_two 
            FROM users U, conversation_reply R, conversation C 
            WHERE R.user_id_fk=U.id and 
                  R.c_id_fk='".$_GET['msg_id']."' and 
                  C.c_id='".$_GET['msg_id']."' 
            ORDER BY R.cr_id ASC") 
        or die(mysql_error());

    while($row=mysql_fetch_array($query))
    {

        if($row['user_one'] == $_SESSION['user_id']) {
            if($row['visto'] == "1") {
                $recvd = "1";
            } else {
                $recvd = "0";
            }
        } else if($row['user_two'] == $_SESSION['user_id']) {
            if($row['visto2'] == "1") {
                $recvd = "1";
            } else {
                $recvd = "0";
            }
        }

        if($recvd=="1") {
        } else {
            echo "MESSAGE CONTENT";
        }
        if($row['user_one'] == $_SESSION['user_id']) {
            mysql_query("UPDATE `conversation_reply` SET  `visto` =  '1' 
                        WHERE  `conversation_reply`.`id_reply` ='".$row['id_reply']."';");
        } else if($row['user_two'] == $_SESSION['user_id']) {
            mysql_query("UPDATE `conversation_reply` SET  `visto2` =  '1' 
                        WHERE  `conversation_reply`.`id_reply` ='".$row['id_reply']."';");
        }
    }
?>

0 个答案:

没有答案