php mysqli_num_rows结果0

时间:2017-04-12 19:12:21

标签: php mysqli

table name is pvt_messages我正在创建一个社交网络网站我正在处理消息收件箱系统。但我没有显示我的数据库中的任何数据..更明显mysqli_num_rows返回0.请guyz告诉我我错在哪里。今天是我的提交:( ..非常感谢!下面是数据库的屏幕截图,我显示我有数据。

<?php
include("inc/header.inc.php");
?>

<h2>Unread Messages:</h2>

<?php

//grab the messeges from database of user
$grab_messages = mysqli_query($db_conx , "SELECT * FROM pvt_messages 
                                           WHERE user_to='$username' 
                                              && opened='no' 
                                              && deleted='no' ");
$numrows = mysqli_num_rows($grab_messages);
if ($numrows != 0) {
    while ($get_msg = mysqli_fetch_assoc($grab_messages)) {
        $id = $get_msg['id']; 
        $user_from = $get_msg['user_from'];
        $user_to = $get_msg['user_to'];
        $msg_title = $get_msg['msg_title'];
        $msg_body = $get_msg['msg_body'];
        $date = $get_msg['date'];
        $opened = $get_msg['opened'];
        $deleted = $get_msg['deleted'];
?>
<script language="javascript">
function toggle<?php echo $id; ?>() {
    var ele = document.getElementById("toggleText<?php echo $id; ?>");
    var text = document.getElementById("displayText<?php echo $id; ?>");
    if (ele.style.display == "block") {
        ele.style.display = "none";
    } else {
        ele.style.display = "block";
    }
}
</script>

<?php
        if (strlen($msg_title) > 50) {
            $msg_title = substr($msg_title, 0, 50)." ...";
        } else 
            $msg_title = $msg_title;

        if (strlen($msg_body) > 150) {
            $msg_body = substr($msg_body, 0, 150)." ...";
        } else
            $msg_body = $msg_body;


        if (@$_POST['setopened_' . $id . '']) {
            //Update the private messages table
            $setopened_query = mysqli_query($db_conx , 
                                    "UPDATE pvt_messages 
                                        SET opened='yes' 
                                     WHERE id='$id'");
        }

        echo "
<form method='POST' action='messages.php' name='$msg_title'>
    <b><a href='$user_from'>$user_from</a></b>
    <input type='button' name='openmsg' value='$msg_title'     onClick='toggle$id()'>
    <input type='submit' name='setopened_$id' value=\"I've Read This\"> 
</form>
<div id='toggleText$id' style='display: none;'>
    <br />$msg_body
</div>
<hr /><br />
";
    }
}else{
    echo "You Don't Have UnRead Any Messages Or You Don't Have Any Message";
}
?>
<h2>Read Messages:</h2>

<?php
//grab the messeges from database of user
$grab_messages = mysqli_query($db_conx , 
                    "SELECT * FROM pvt_messages 
                    WHERE user_to='$username' 
                       &&opened='yes' 
                       && deleted='no' ");
$numrows_read = mysqli_num_rows($grab_messages);
echo $numrows_read;
if ($numrows_read != 0) {
    while ($get_msg = mysqli_fetch_assoc($grab_messages)) {
        $id = $get_msg['id']; 
        $user_from = $get_msg['user_from'];
        $user_to = $get_msg['user_to'];
        $msg_title = $get_msg['msg_title'];
        $msg_body = $get_msg['msg_body'];
        $date = $get_msg['date'];
        $opened = $get_msg['opened'];
        $deleted = $get_msg['deleted'];
  ?>
<script language="javascript">
function toggle<?php echo $id; ?>() {
    var ele = document.getElementById("toggleText<?php echo $id; ?>");
    var text = document.getElementById("displayText<?php echo $id; ?>");
    if (ele.style.display == "block") {
        ele.style.display = "none";
    }else{
        ele.style.display = "block";
    }
}
</script>

<?php
        if (strlen($msg_title) > 50) {
            $msg_title = substr($msg_title, 0, 50)." ...";
        }else
            $msg_title = $msg_title;

        if (strlen($msg_body) > 150) {
            $msg_body = substr($msg_body, 0, 150)." ...";
        }else
            $msg_body = $msg_body;

        if (@$_POST['delete_' . $id . '']) {
            $delete_msg_query = mysqli_query($db_conx , 
                    "UPDATE pvt_messages 
                    SET deleted='yes' WHERE id='$id'");
        }
        if (@$_POST['reply_' . $id . '']) {
            echo "<meta http-equiv=\"refresh\" content=\"0; url=msg_reply.php?  u=$user_from\">";
        }

        echo "<form method='POST' action='messages.php' name='$msg_title'>
  <b><a href='$user_from'>$user_from</a></b>
  <input type='button' name='openmsg' value='$msg_title'   onClick='toggle$id()'>
  <input type='submit' name='delete_$id' value=\"X\" title='Delete Message'>
  <input type='submit' name='reply_$id' value=\"Reply\">
  </form>
  <div id='toggleText$id' style='display: none;'>
  <br />$msg_body
  </div>
  <hr /><br />";
    }
}else{
    echo "You haven't read any messages yet.";
}
?>

0 个答案:

没有答案