group inbox messages by day

Started on the old forum in May 2012 · view the original in the archive · old links redirect here

1 reply · 471 views · started 14 years ago · 1 min read

2 participants
pmbguy Senior · 344 posts #1

ok, i am coding script, message table similat to lava if from user, touser, date, etc... i added year month n day trying to get following code to work, should list messages like skype ie: each day in separate div... but i got a bug somewhere, was working yesterday, now sticking on last day n i can't figure out what i done, n its doing my head in now lol... n thought i'd post here since I'm guessing others might like code... Really simple, but got one bug...

echo "<div id='convo_box'>";
if($page=="" || $page<=0)$page=1;
$noi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM bl0gger_messages WHERE (touser='$username' AND fromuser='$whofrom') OR (touser='$whofrom' AND fromuser='$username')"));

    $num_items = $noi[0]; //changable
    $items_per_page= 20;
    $num_pages = ceil($num_items/$items_per_page);
    if(($page>$num_pages)&&$page!=1)$page= $num_pages;
    $limit_start = ($page-1)*$items_per_page;

    //changable sql

echo "<div style='background:black; color:white;' align='center'>$username - $whofrom</div><br/>";
          $sql = "SELECT DISTINCT(day) FROM bl0gger_messages WHERE (touser='$username' AND fromuser='$whofrom') OR (touser='$whofrom' AND fromuser='$username') ORDER BY id DESC LIMIT 20";

    $items = mysql_query($sql);
    if(mysql_num_rows($items)>0)
    {

    while ($item = mysql_fetch_array($items))
    {
    echo "<div style='border:1px black ridge;' align='left'>$item[0]<br/>";
    /////////////
    $sql = "SELECT id, touser, fromuser, msgtext, msgtime, seen FROM bl0gger_messages WHERE (touser='$username' AND fromuser='$whofrom'  AND day='$item[0]') OR (touser='$whofrom' AND fromuser='$username'  AND day='$item[0]') ORDER BY id DESC";

    /////////////
        $items = mysql_query($sql);
    $x = 1;
    if ($x=="1"||$x=="3"||$x=="5"||$x=="7"||$x=="9")
    {
     $nickcol = "blue";
    }
    else
    {
     $nickcol = "red";
    }
    if(mysql_num_rows($items)>0)
    {
    while ($item = mysql_fetch_array($items))
    {
      $text = getbbcode($item[3]);
      echo "<div align='left'>";
      echo "<font color='$nickcol'>$item[2]</font> -> $text<br/>";
      echo "<small>Sent: ".date('l jS \of F Y h:i:s A', $item[4])."</small>";

      echo "</div>";
    }
    }
    echo "</div>";
    }

 }

enjoy, n please assist someone!!!

ori Lead · 512 posts #2

dont have xactly that but i sorted shoutbox history by days heres what i use so should be useful in creating your code

page = $_request['page']?$_request['page']:1;
$time = strtotime("-".($page-1)." day");
$day_date = date("Y-m-d",$time);
$query = mysql_query("SELECT * FROM extras WHERE type = 'S' AND date = '$day_date' ORDER BY time DESC");

that will sort them by pages under day so page 1 will be current day and page 2 yesterday etc

to get day names use this

date("D",strtotime('-1 day')); \\yesterday
date("D",strtotime('-2 day')); \\day before yesterday etc

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close