我正在尝试创建一个内部消息传递系统。
我的代码如下:
$useraccess = $loggedInUser->username;
$sql = "SELECT id, user_name FROM ".$db_table_prefix."users WHERE user_name='$useraccess'";
$query = $mysqli->query($sql) or die ("Error");
while ($row = mysqli_fetch_array($query)) {
$pid = $row["id"];
$username = $row["user_name"];
}
$query->close();
$sqlCommand = "SELECT COUNT(id) AS numbers FROM ".$db_table_prefix."messages_inbox WHERE userid='$pid'";
$query = $mysqli->query($sql) or die ("Error");
$result = mysqli_fetch_assoc($query);
$inboxMessages = $result['numbers'];
?>
<h1>Inbox</h1>
<?php
$sql="SELECT * FROM ".$db_table_prefix."messages_inbox WHERE userid='$pid' ORDER by id DESC";
$result=$mysqli->query($sql);
$count=mysqli_stmt_num_rows($result);
?>
<p>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<th style="text-align: left; ">Title</th>
<th style="text-align: right; ">Sender</th>
<th style="text-align: right; "><b>Actions</b></th>
</tr>
<?php
while($rows=mysqli_field_count($result)) {
?>
<?php if ($rows['viewed'] == 0) { // show messages in bold?>
<tr>
<td style="text-align: left; "><a href="messages-view-in.php?in=<?php echo $rows['id']; ?>"><b><?php echo $rows['title']; ?></b></a></td>
<td style="text-align: right; "><?php echo $rows['from_username']; ?></td>
<td style="text-align: right; "><a href="messages-inbox-delete.php?message=<?php echo $rows['id']; ?>">Delete</a></td>
</tr>
<?php } else if ($rows['viewed'] == 1) { ?>
<tr>
<td style="text-align: left; "><a href="messages-view-in.php?in=<?php echo $rows['id']; ?>"><?php echo $rows['title']; ?></a></td>
<td style="text-align: right; "><?php echo $rows['from_username']; ?></td>
<td style="text-align: right; "><a href="messages-inbox-delete.php?message=<?php echo $rows['id']; ?>">Delete</a></td>
</tr>
<?php } ?>
<?php } ?>
</table>
<?php if ($inboxMessages > 0) { ?>
<?php } else
{ print "<div id=\"errors\">Currently you do not have messages in your Inbox</div>";
} ?>
这是我试图在其中显示来自数据库的数据的收件箱。它连接没问题,否则会抛出错误,所以我相信这是我的语法。
我收到以下错误。
Warning: mysqli_stmt_num_rows() expects parameter 1 to be mysqli_stmt, object given in /opt/lampp/htdocs/project/inbox.php on line 28
Warning: mysqli_field_count() expects parameter 1 to be mysqli, object given in /opt/lampp/htdocs/project/inbox.php on line 38
Notice: Undefined index: numbers in /opt/lampp/htdocs/project/inbox.php on line 20