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!


Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Jul 2008
    Posts
    535
    Tokens
    75

    Default [PHP] Private Message Help

    PHP Code:
    <?php

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

    $query mysql_query("SELECT * FROM `private_messages` WHERE `to` = '"$sess_username."'");
    $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."'");

    echo (
    $today);

    while (
    $display mysql_fetch_array($query1)){
    if(
    $pm_count == 0){
        echo 
    'You do not have any messages at this time.';
    } else{
            
    $query1 mysql_query("SELECT * FROM private_messages WHERE date='".$today."' AND to='".$sess_username."'")or die(mysql_error());
            if(
    mysql_num_rows($query1) > 0){
                   echo 
    "<b>Today</b><br />";
                   while(
    $display=mysql_fetch_array($query1)){
            if(
    $read === 0){ echo "<b>";
                echo 
    "</b>";
                echo 
    $display["title"]." - ".$display["from"];
                echo 
    "<br />"
                   } else {
                echo 
    "</b>";
                echo 
    $display["title"]." - ".$display["from"];
                echo 
    "<br />";
                   }
            }
          }
          
          
          
            
    $query2 mysql_query("SELECT * FROM private_messages WHERE date='".$yesterday."' AND to='".$sess_username."'")or die(mysql_error());
            if(
    mysql_num_rows($query2) > 0){
                   echo 
    "<b>Yesterday</b><br />";
                   while(
    $display=mysql_fetch_array($query2)){
            if(
    $read === 0){ echo "<b>";
                echo 
    "</b>";
                echo 
    $display["title"]." - ".$display["from"];
                echo 
    "<br />"
                   } else {
                echo 
    "</b>";
                echo 
    $display["title"]." - ".$display["from"];
                echo 
    "<br />";
                   }
            }
          }
    $query3 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($query3)){
               if(
    $display["date"]==$lastdate){
            if(
    $read === 0){ echo "<b>";
                echo 
    "</b>";
                echo 
    $display["title"]." - ".$display["from"];
                echo 
    "<br />"
                   } else {
                echo 
    "</b>";
                echo 
    $display["title"]." - ".$display["from"];
                echo 
    "<br />";
                   }
            }
          }
        
    $lastdate=$display["date"];
        echo 
    "<b>".$lastdate."</b><br />";
            if(
    $read === 0){ echo "<b>";
                echo 
    "</b>";
                echo 
    $display["title"]." - ".$display["from"];
                echo 
    "<br />"
               } else {
                    echo 
    "</b>";
                echo 
    $display["title"]." - ".$display["from"];
                echo 
    "<br />";
       }
      }
     }
    }        
    ?>
    I've come back to coding PHP, and I'm starting a simple script. I'm having aporblem though, it's not displaying any PM's (there's only 1 in the database) I echoed what the $today variable comes out as, and it says 09.05.2008. I enetered that in the 'date' column for the PM and nothing showed up. Anybody know what's up with it? +rep

    EDIT: I'm now getting the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to='Will'' at line 1

    Which has to do witht he following code:
    PHP Code:
    $query mysql_query("SELECT * FROM `private_messages` WHERE `to` = '".$sess_username."'"); 
    Last edited by wsg14; 06-09-2008 at 12:11 AM.

  2. #2
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    $query mysql_query("SELECT * FROM `private_messages` WHERE `to` = '$sess_username'"); 

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

    Default

    It still gives me that error.

  4. #4
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    You need to rename the row "to" to something else.
    Lets set the stage on fire, and hollywood will be jealous.

  5. #5
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    To is a MySQL reserved word, backticks should not produce this error, but it will still become very confusing use something like pmTo, pmFrom, etc. Also, you don't need to concatenate variables to strings if you are using double quotes.

    This is a bug not an error. Your <b> to denote a unread message is not enclosed around the message name.

    Don't use parenthesis in language constructs. Language constructs are usually (in your ide) highlighted as green, like echo, include, etc.

    I don't understand your logic for a read pm.

    Add a column to your table called pmRead and have it as a tinyint(1) defaulted to 0, and then instead of using if($read === 0), use if(!$row['read']), also when your doing triple-equals/=== you could cut down code and just use if($var) as opposed to if($var === 1).

    When using dates in MySQL, I'd advise you to use MySQLs DATETIME, it's quite good for doing date checks as you can use mysql's BETWEEN keyword to check for dates, a lot easier than unix time, it comes like MM-DD-YYYY 00:00:00, correct me if I'm wrong.

    Try and neaten up your code and name variables more semantically, it might be easy for you to remember as you coded it, but it becomes quite difficult when people get confused between $query, $query1, $query2, etc.

    Nitpick: When using things like $display["title"], use single quotes, as you can't use variables within single quotes, it will speed up execution time as it doesn't have to check for variables etc. Post your code again when you've renamed things.

    Oh, also, it makes it easier to read if you stick with one way of spacing like:
    Sometimes you'll use spaces, and sometimes you won't, especially in your MySQL queries, it gets hard to read when everythings together like

    PHP Code:
    $query3 mysql_query("SELECT * FROM private_messages WHERE `date`!='".$today."' AND `date`!='".$yesterday."' AND `to`='".$sess_username."'")or die(mysql_error()); 
    You have things like `date`!='".$today."' AND should be:
    PHP Code:
    `date` != '$today' AND 
    ...much easier to read.

    Also can you explain what $lastdate actually does.
    How could this hapen to meeeeeeeeeeeeeee?lol.

  6. #6
    Join Date
    Sep 2008
    Location
    UK
    Posts
    3,670
    Tokens
    0

    Latest Awards:

    Default

    *REMOVED*

    Edited by Flisker (Forum Moderator): Please do not be rude to forum members
    Last edited by Flisker; 07-09-2008 at 12:41 AM.

  7. #7
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Excellent2 View Post
    *REMOVED*

    Edited by Flisker (Forum Moderator): Please do not be rude to forum members
    Moderator's approve posts, how did it get through to be edited.

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

    Default

    Thanks for the advice Charlie, it helped a bit. I'm still having aproblem though. it's now display double of the "Today" column, and it's also display the PM not only form today, but from yesterday too. (all under the Today column). It looks like this:

    Today
    hey - guy
    yo - guy
    Today
    hey - guy
    yo - guy

    It also isn't coming up bold.

  9. #9
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Can you repost your current code?

    Thanks.
    How could this hapen to meeeeeeeeeeeeeee?lol.

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

    Default

    Sorry, thought I did.

    PHP Code:
    <?php

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

    $query mysql_query("SELECT * FROM `private_messages` WHERE `pmto` = '".$sess_username."'");
    $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 `pmto` = '".$sess_username."'");

    while (
    $display mysql_fetch_array($query)){
    if(
    $pm_count === 0){
        echo 
    'You do not have any messages at this time.';
    } else{
            
    $query1 mysql_query("SELECT * FROM `private_messages` WHERE `date` ='".$today."' AND `pmto` ='".$sess_username."'")or die(mysql_error());
            if(
    mysql_num_rows($query1) > 0){
                   echo 
    "<b>Today</b><br />";
                   while(
    $display mysql_fetch_array($query1)){
            if(
    $read === 0){ echo "<b>";
                echo 
    $display['title']." - ".$display['from'];
                echo 
    "</b>";
                echo 
    "<br />"
                   } else {
                echo 
    "</b>";
                echo 
    $display['title']." - ".$display['from'];
                echo 
    "<br />";
                   }
            }
          } else {}
              
              
    $query2 mysql_query("SELECT * FROM `private_messages` WHERE `date`='".$yesterday."' AND `pmto`='".$sess_username."'")or die(mysql_error());
            if(
    mysql_num_rows($query2) > 0){
                   echo 
    "<b>Yesterday</b><br />";
                   while(
    $display1 mysql_fetch_array($query2)){
            if(
    $read === 0){ echo "<b>";
                echo 
    "</b>";
                echo 
    $display1['title']." - ".$display1['from'];
                echo 
    "<br />"
                   } else {
                echo 
    "</b>";
                echo 
    $display1['title']." - ".$display1['from'];
                echo 
    "<br />";
                   }
            }
          } else {}
           
    $query3 mysql_query("SELECT * FROM `private_messages` WHERE `date` !='".$today."' AND `date` !='".$yesterday."' AND `pmto` ='".$sess_username."'")or die(mysql_error());
          while(
    $display2 mysql_fetch_array($query3)){
            if(
    $read === 0){ echo "<b>";
                echo 
    "</b>";
                echo 
    $display2['title']." - ".$display2['from'];
                echo 
    "<br />"
                   } else {
                echo 
    "</b>";
                echo 
    $display2['title']." - ".$display2['from'];
                echo 
    "<br />";
                   }
            }
          }
       }
      }    
    ?>

Page 1 of 2 12 LastLast

Posting Permissions

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