Jump to content
MakeWebGames

mailbox/events as widget


Recommended Posts

$db->query("SELECT * FROM `mail` WHERE `mail_to` = '".$_SESSION['id']."' ORDER BY `mail_time` DESC LIMIT 20");

I selected * because the only row we didn't need was mail_read and the extra typing wasn't worth it.

 

 

Edited by Zettieee
Forgot DESC
Link to comment
Share on other sites

echo ($mc > 0)
       ? 'Mailbox (' . $mc . ')' : 'Mailbox (0)';

         echo "</th>
         </tr>
         <tr>
           <td>";

  if ($mc > 0){
      echo "<a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a>   {$r['mail_subject']}";
       }                  
    else    {
    echo "<a href='mailbox.php'> No Messages</a>";
    }

 

But doesn't show any messages right now (maybe because they aren't new)?

Also, now I have 2 undefined warnings. I tried

$id = session_id();

but no luck

Edited by boionfire81
Link to comment
Share on other sites

echo ($mc > 0)
? 'Mailbox (' . $mc . ')' : 'Mailbox (0)';

echo "</th>
</tr>
<tr>
<td>";

if ($mc > 0){
echo "<a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a>   {$r['mail_subject']}";
}
else {
echo "<a href='mailbox.php'> No Messages</a>";
}

 

But doesn't show any messages right now (maybe because they aren't new)?

Also, now I have 2 undefined warnings. I tried

$id = session_id();

but no luck

 

That would be because the $mc is only counting numbers showing the user how many mails/events they have what your wanting to do is a little more complicated

as Zettieee said he pulled the mails from the mail table randing from users id and ordered it by time then limited it to 20 which will only grab the first 20

now adapting onto Zettieee code you will need to add some extra stuff for this to work.

 


$grabmails = $db->query("SELECT `mail_time`,`mail_subject`,`mail_text` FROM `mail` WHERE `mail_to` = ".$userid." AND `mail_read` = 0 ORDER BY `mail_time` DESC LIMIT 20");
while($gm = $db->fetch_row($grabmails)) {
// cut messae down to 20 characters
$qm = substr($gm['mail_text'], 0, 20);
}

 

ill let you figure out the rest :)

 

Link to comment
Share on other sites

Well the first error was the quotes had to be changed to avoid a fatal. Then I toggled with the mailread = 0, and then the variabes. Basically in the end the best I got was a blank area. Not a good sign, but considering 9/10 tries ended in a No Messages, despite there being 8 messages. -.-

Link to comment
Share on other sites

  • 5 weeks later...

Thought I'd post this now that it is finished

Mailbox widget

          

   $mm =
           $db->query(
                   "SELECT `m`.*, `userid`, `username`
                    FROM `mail` AS `m`
                    LEFT JOIN `users` AS `u`
                    ON `m`.`mail_from` = `u`.`userid`
                    WHERE `m`.`mail_to` = $userid
                    ORDER BY `mail_time` DESC
                    LIMIT 3");
   while ($r = $db->fetch_row($mm))
   {


       if ($r['userid'])
       {
           echo "<b>From:</b> <a href='viewuser.php?u={$r['userid']}'><font color=black>{$r['username']}</font></a><br>";
       }
       else
       {
           echo "<br><b>From: <font color=red>SYSTEM</font></b>";
       }
        $sent = date('n/d/y g:i', $r['mail_time']);
       echo "$sent";
   // cut messae down to 20 characters
   $qm = substr($r['mail_text'], 0, 100);

      echo "<br>{$qm}<br /><br />";
       }                   

    echo "<a href='mailbox.php'>View Mailbox...</a></td></tr></table><br>";

 

Events widget

$ed =
       $db->query(
               "SELECT `evTIME`, `evREAD`, `evTEXT`, `evID`
               FROM `events`
               WHERE `evUSER` = $userid
               ORDER BY `evTIME` DESC
               LIMIT 3");
echo"<table class='menu'><tr><th>Events</th></tr>";              
while ($t = $db->fetch_row($ed))
{
   echo "<tr><td>" . date('n/d/y g:i', $t['evTIME']);
   if (!$t['evREAD'])
   {
       echo '   <font color="#CE0101">New!</font>';
   }
   echo "</td></tr><tr><td>{$t['evTEXT']}</td></tr>";
}

   echo "<tr><td><a href='events.php'>View Events...</a></td></tr></table>";
Link to comment
Share on other sites

  • 3 weeks later...
# Use LEFT() in mysql, to cut a string shorter;
$sql = "SELECT LEFT(mail_text, 20) AS mail_text, mail_time, userid, username FROM mail
       LEFT JOIN users ON (mail_from = userid)
       WHERE mail_to = $userid 
       ORDER BY mail_id DESC LIMIT 3;";
$rs = $db->query($sql);

# Make sure you make sure you have results to loop through;
if ($db->num_rows($rs)) {

 while ($row = $db->fetch_row($rs)) {

   if ($row['userid']) {
     echo "<b>From:</b> <a href='viewuser.php?u={$row['userid']}'><font color=black>{$row['username']}</font></a><br>";
   } else {
     echo "<br><b>From: <font color=red>SYSTEM</font></b>";
   }

   # Echo straight to screen if you have nothing to do with a variable you're casting;
   echo date('n/d/y g:i', $row['mail_time']);

   # Cut out all the processing of the string, if you use LEFT - as said above;
   echo '<p>'.$row['mail_text'].'</p>';
 }
}
echo "<a href='mailbox.php'>View Mailbox...</a></td></tr></table><br>";  
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...