boionfire81 Posted April 16, 2016 Share Posted April 16, 2016 Anyone know how to implement the mailbox (subject, from, time) & first 20 characters of new events into widgets? I'm wanting to put them in my sidebar. Quote Link to comment Share on other sites More sharing options...
Zettieee Posted April 16, 2016 Share Posted April 16, 2016 (edited) $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 April 16, 2016 by Zettieee Forgot DESC Quote Link to comment Share on other sites More sharing options...
boionfire81 Posted April 17, 2016 Author Share Posted April 17, 2016 (edited) 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 April 17, 2016 by boionfire81 Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted April 17, 2016 Share Posted April 17, 2016 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 :) Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted April 17, 2016 Share Posted April 17, 2016 Take a look at this: http://lab.mbuonomo.com/notificationcenter/ or: http://thesin-.github.io/notificationcenter/ which is based on the first link. But this one is more like OS X style Quote Link to comment Share on other sites More sharing options...
boionfire81 Posted April 17, 2016 Author Share Posted April 17, 2016 Dude -.- yeah even that produced a bunch of errors. Right about now, my brain is to fried to even think...I would post code but I've tried the () & {} % vs $ then the '..' bro!!! Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted April 17, 2016 Share Posted April 17, 2016 What exactly were your errors? It's real hard to help without the info Quote Link to comment Share on other sites More sharing options...
boionfire81 Posted April 17, 2016 Author Share Posted April 17, 2016 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. -.- Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted April 17, 2016 Share Posted April 17, 2016 Hmm, I'm not seeing an issue with what NSC and Zet have posted. Is there a way you can post what you have and any errors or whatever that you are getting? And also your HTML markup too Quote Link to comment Share on other sites More sharing options...
boionfire81 Posted April 17, 2016 Author Share Posted April 17, 2016 Will do that tomorrow. I went through about 30 variations though, so will take awhile. If it was a simple one or two would be easier. But....tomorrow Quote Link to comment Share on other sites More sharing options...
boionfire81 Posted May 17, 2016 Author Share Posted May 17, 2016 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>"; Quote Link to comment Share on other sites More sharing options...
SRB Posted June 4, 2016 Share Posted June 4, 2016 # 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>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.