I have it setup where you have your inbox, where all u're messages are at. Then there is a place to write messsages and a place to save messages. The saved messages do not show up in the inbox; only the new messages and the read messages that are not saved.
How would I go about using the if statement for when there are NO messages displayed in the inbox. I guess it would mean there were no NEW messages, and no messages that one has already read. I have a readm in the database that equals 0 if the message has been read, and a saved in the database that equals yes if they message has been saved and no if it's not been saved. Below is the working code I have for the inbox. But when I have saved or deleted all messages, I get these errors, which I assume it's wanting something to be taken from the database, but nothing is there, so it gives this error:
Code: Select all
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\login2\mafiawarskingdom.php on line 702
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\login2\mafiawarskingdom.php on line 725
Code: Select all
$sql = "SELECT * FROM messages WHERE pid='$user_username' AND saved='no' ORDER BY date DESC, readm=1 DESC $limit";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
Code: Select all
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
Code: Select all
<?php //******************** BEGINNING OF USERS MESSAGING INBOX SYSTEM ********************// ?>
<?php
if(isset($_GET['messages'])) {
?>
<!DOCTYPE html>
<html>
<head>
<title>Tabbed Content</title>
<script src="tabcontent.js" type="text/javascript"></script>
<link href="style/tabcontent.css" rel="stylesheet" type="text/css" />
</head>
<body style=" font-family:Arial;">
<div style="width: 700px; margin: 0 auto; padding: 120px 0 40px;">
<ul class="tabs" data-persist="true">
<li><a href="#view1"><b><big>Inbox</a></big></b></li>
<li><a href="#view2"><b><big>Send Messages</a></big></b></li>
<li><a href="#view3"><b><big>Saved Messages</a></big></b></li>
</ul>
<div class="tabcontents">
<div id="view1">
<p>
<?php
$bypass = 0;
if($bypass != 1)
{
if(isset($_GET['messages']) || isset($_POST['messages']))
{
$bypass = 1;
$sql = "SELECT * FROM messages WHERE pid='$user_username' AND saved='no' ORDER BY date DESC, readm=1 DESC";
$user_query = mysqli_query($db_conx, $sql);
$nr = mysqli_num_rows($user_query);
echo "<left>";
echo "<table border = '0' width = '100%' cellspacing = '5'>";
if (isset($_GET['pn'])) {
$pn = preg_replace('#[^0-9]#i', '', $_GET['pn']);
} else {
$pn = 1;
}
$itemsPerPage = 5;
$lastPage = ceil($nr / $itemsPerPage);
if ($pn < 1) {
$pn = 1;
} else if ($pn > $lastPage) {
$pn = $lastPage;
}
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $add1 . '">' . $add1 . '</a> ';
} else if ($pn == $lastPage) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $sub2 . '">' . $sub2 . '</a> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $add1 . '">' . $add1 . '</a> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $add2 . '">' . $add2 . '</a> ';
} else if ($pn > 1 && $pn < $lastPage) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $add1 . '">' . $add1 . '</a> ';
}
$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;
$sql = "SELECT * FROM messages WHERE pid='$user_username' AND saved='no' ORDER BY date DESC, readm=1 DESC $limit";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
$paginationDisplay = "";
if ($lastPage != "1"){
$paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. ' ';
if ($pn != 1) {
$previous = $pn - 1;
$paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $previous . '"> Back</a> ';
}
$paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
if ($pn != $lastPage) {
$nextPage = $pn + 1;
$paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $nextPage . '"> Next</a> ';
}
}
$outputList = '';
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
$row['subject'] = left($row['subject'], 20) . "...";
if($row['readm'] == 1) {
$outputList .= "
<td><left><font color = 'red'>NEW!</font></td>
<td><left>$row[sender] <td>
<td><left>$row[subject] </td>
<td><left>$row[date] </td>
<td><right><form method='post' action='mafiawarskingdom.php?messages=1'><input type='submit' value='Read'>
<input type='hidden' name='readmessage' value='1'>
<input type='hidden' name='randid' value='$row[randid]'>
<input type='hidden' name='date' value='$row[date]'></td></tr>
</form>";
}
else
{
$outputList .= "
<td></td>
<td><left>$row[sender] <td>
<td><left>$row[subject] </td>
<td><left>$row[date] </td>
<td><right><form method='post' action='mafiawarskingdom.php?messages=1'><input type='submit' value='Read'>
<input type='hidden' name='readmessage' value='1'>
<input type='hidden' name='randid' value='$row[randid]'>
<input type='hidden' name='date' value='$row[date]'></td></tr>
</form>";
}
}
}
?>
</div>
<div style="padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div>
<div align="left"><?php echo "$outputList"; ?></div>
<?php
}
echo "</table>";
echo "</td></tr></table>";
echo "</small>";
?>
<div style="padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div>
<?php //******************** ENDING OF USERS MESSAGING INBOX SYSTEM ********************// ?>
I've tried tons of combinations of the if and else statement to get it where it shows "There are no messages in your inbox at this time" or something like that, but all I ever get is that error. And I'm not sure how to go about it because of the row readm and saved in the database. Thanks for any help!