Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2008
    Posts
    535
    Tokens
    75

    Default A couple problems [PHP]

    PHP Code:
    <?php

    if($logged['in'] === 0){
        
    header("Location: index.php");
    } else {

    $query mysql_query("SELECT * FROM `private_messages` WHERE `to` = '".$sess_username."' ORDER BY date DESC");
    $pm_count mysql_num_rows($query);
    $today date("m.d.Y");
    $yesterday mktime(000date'm' )  , date'd' ) - 1date'y' ));
    $read mysql_query("SELECT `read` FROM `private_messages` WHERE `to` = '".$sess_username."'");

    while (
    $display mysql_fetch_array($query)){
    if(
    $pm_count == 0){
        echo 
    'You do not have any messages at this time.';
    } else{
        if(
    $query->date == $today){
            echo 
    '<b>Today</b><br />';
            if(!
    $read == 0){
                echo 
    "<b>" $display['title'] . " - " $display['from'] . "</b><br />";
            } else {
                echo 
    $display['title'] . " - " $display['from'] . "<br />";
            }
        }
        if(
    $query->date == $yesterday){
            echo 
    '<b>Yesterday</b><br />';
            if(!
    $read == 0){
                echo 
    "<b>" $display['title'] . " - " $display['from'] . "</b><br />";  
            } else {
                echo 
    $display['title'] . " - " $display['from'] . "<br />";  
            }
        }
        if(!
    $read == 0){
            echo 
    $display['date'] . "<br />";
            echo 
    "<b>" $display['title'] . "-" $display['from'] . "</b><br />";
        } else {
            echo 
    $display['date'] . "<br />";
            echo 
    $display['title'] . "-" $display['from'] . "</b><br />";
        }
    }
    }
    }
    ?>
    With that, code basically I want the PM's to show like this:

    Today
    yo - user1

    Yesterday
    brb - user2

    01.01.01
    nah - user3

    etc.
    But with that code it's showing this:
    Yesterday
    lolol - a guy
    07-27-2008
    lolol-a guy
    First problem is that it's showing 1 message twice, in two different time frames (07-27-2008 - that's what is in the DB for 'date').

    I cannot seem to find out why it's doing that. Many thanks to whoever fixes it.

    Moved by Invent (Forum Moderator) from Designing & Development: Please post in the correct forum next time, thanks .
    Last edited by Invent; 27-07-2008 at 11:26 PM.

  2. #2
    Join Date
    Jul 2008
    Posts
    535
    Tokens
    75

    Default

    Forgot to post the second problem.

    Which is: the date in the DB is today's date but it's still categorized under yesterday.

  3. #3
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    I'll have a read through later, just I'm a lazy ***. So if invent/dentafrice/whoever doesn't get to it i'll have a read through.


    www.fragme.co = a project.

  4. #4
    Join Date
    Jul 2008
    Location
    Leeds, UK
    Posts
    47
    Tokens
    0

    Talking The Fix [I Think]

    PHP Code:
    <?
    if($logged['in'] === 0){
        
    header("Location: index.php");
    } else {
     
    // Check for PM's
     
    $query mysql_query("SELECT * FROM private_messages WHERE to='".$sess_username."'")or die(mysql_error());
     if(
    mysql_num_rows($query)=="0"){
      echo 
    "You do not have any messages at this time.";
     } else {
      
    // Dates
      
    $today date("d.m.Y");
      
    $yesterday date("d.m.Y"mktime(000date("m") , date("d")-1date("y")));
      
    // Today
      
    $query mysql_query("SELECT * FROM private_messages WHERE date='".$today."' AND to='".$sess_username."'")or die(mysql_error());
      if(
    mysql_num_rows($query)){
       echo 
    "<b>Today</b><br />";
       while(
    $display=mysql_fetch_array($query)){
        if(!
    $display[read]) echo "<b>";
        echo 
    $display["title"]." - ".$display["from"];
        if(!
    $display[read]) echo "</b>";
        echo 
    "<br />"
       }
      }
     
      
    // Yesterday
      
    $query mysql_query("SELECT * FROM private_messages WHERE date='".$yesterday."' AND to='".$sess_username."'")or die(mysql_error());
      if(
    mysql_num_rows($query)){
       echo 
    "<b>Yesterday</b><br />";
       while(
    $display=mysql_fetch_array($query)){
        if(!
    $display[read]) echo "<b>";
        echo 
    $display["title"]." - ".$display["from"];
        if(!
    $display[read]) echo "</b>";
        echo 
    "<br />"
       }
      }
     
      
    // Other Dates
      
    $query mysql_query("SELECT * FROM private_messages WHERE `date`!='".$today."' AND `date`!='".$yesterday."' AND `to`='".$sess_username."'")or die(mysql_error());
      
    $lastdate="";
      while(
    $display=mysql_fetch_array($query)){
       if(
    $display["date"]==$lastdate){
        if(!
    $display[read]) echo "<b>";
        echo 
    $display["title"]." - ".$display["from"];
        if(!
    $display[read]) echo "</b>";
        echo 
    "<br />"
       } else {
        
    $lastdate=$display["date"];
        echo 
    "<b>".$lastdate."</b><br />";
        if(!
    $display[read]) echo "<b>";
        echo 
    $display["title"]." - ".$display["from"];
        if(!
    $display[read]) echo "</b>";
        echo 
    "<br />";
       }
      }
     }
    }
    ?>
    Instead of going through each message. It should of been done by date.
    Get all the private messages from today = +1 query.
    Get all the private messages from yesterday = +1 query.
    Get all the private messages excluding today and yesterday = +1 query.

    For the last bit aswell i had to put on a lastdate to check if its still in the right group other wise it would come out like

    01.01.01
    nah - user 3

    01.01.01
    nah2 - user 4

    ect. ect.

    Any problems with it post and i'll see if i can spot the error but looking through it now i doubt i can find any error, i would test the script but i only just reinstalled my laptop and dont have a php server running yet. sry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •