Jump to content

Zane

Administrators
  • Posts

    4,362
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Zane

  1. Exactly. after so many minutes you can consider a user inactive and at that point you can do a number of things.

    You could

    - destroy their session ... logging them out completely

    - keep their session allowing them to stay online but appear offline

    - create some sort of popup telling the user they have been logged out for inactivity like most bank portals do

    - well, I suppose that is about the most you could do...without redirecting them to google or something.

  2. The error means exactly what is says it means..

    Call to a function of a non-object

     

    A non-object indicates that there is no object to be pulling a function from. I willing to bet that it has to do with you using globals,...incorrectly

    In PHP global variables must be declared global inside a function

    That quote is from the manual.

     

    Also, you shouldn't even be using globals. You have already included the file with the $db declaration...ie pdo_conn.php, Making it global is redundant. You might also want to check whether or not your pdo_conn.php file is actually being included

  3. Yeah the "flag" isn't really necessary. I just put that there to explain how to record a description of the activity. Like in IPB when you post a reply it grabs a certain script and appends something like do=postreply which is then sent to a switch I am assuming and an activity description is created.... $username . "is posting a reply in " . $topic..

     

    But yea... the flag isn't necessary if you aren't recording such things.

  4. Let's say you have a link somewhere for say... reports. In the href of this link, you would add a flag variable to it like

    Reports

    Then on your reports.php page, you would check for that flag, create a timestamp if it is there and then update the database. You could roll all of that up into a single function

     

    Of course, you can only run this function if a user is logged in. So do that check first.

     

    When they log out, you can update that column to NULL.

     

    All you are doing is taking the exact time of when they click a link or something else and putting that time into the database. You would also put this time into the SESSION variable for quicker access.

     

    Once you have that, you find your existing queries and while loops for getting the info about your users. If the time in the activity column is older than 15, 20, 30 ..whatever minutes you feel like using, then they are offline.

     

    You can have your SQL return you a boolean for online.

     

    SELECT *, CASE  
    WHEN TIMESTAMPDIFF(MINUTE , activity, NOW()) > 15
    THEN 0 
    ELSE 1
    END AS isOnline
    

     

    Then, in your PHP script you can use a simple ternary statement to display Online or Offline

     

    $onlineStatus = $row['isOnline'] ? "Online" : "Offline"

  5. Like Jessica said, you will have to keep track of everything they do. Simply storing the timestamp of when they logged in will not cut it. In a forum like this, every thing is registered and logged.. simply clicking this reply box counts as me being online. What you will have to do in the long run is restructure your current system to log everything and anything... the more you log the more accurate your online/offline status will be.

     

     

    And no, I am not suggesting that you create a table for all of these logs. You simply need two extra columns in your table. One to describe the action and the other to hold the timestamp... or DATETIME format which would be a lot more efficient.

  6. Unless you are still using PHP4, there is no need to use the POSIX regular expression engine. ..aka ereg. You are much better off using PCRE aka... preg to validate. I especially do not understand the use of the multibyte function mainly because I have never used it myself... and I have been able to validate phone numbers just fine without it

     

    Something like this should work just fine for a phone number

    if(preg_match("#[0-9{3}-[0-9]{3}-[0-9]{4}#", $phoneNumber)) echo "valid phone number"
    

     

    Although it isnt the most common and popular way of doing, it should get you on the right track.

  7. <a href="article.php/<?php $news->Title()?>">

    According to your code, the method Title() does the echo. Using OOP, you do not echo data inside the class. You strictly return data. This way, you can do something like this

     

    <a href="article.php/<?php echo str_replace(' ', '-', $news->Title()) ?>">

     

    So, go into your class file and change your Title method to return $variable instead of echo $variable.

  8. Using a left float works fine for me. Not sure why it doesnt work in the ID style.

     

    Then again, you are going about this all wrong. You are created the exact same styles for different IDs. IDs are meant to be unique, distinct, different. You need to be using classes for your pictures. Add a classname to your dynamic divs and create ONE style tag for that.

     

    echo "<style type=\"text/css\">
    $div {
    width: 162px;
    height: 121px;
    display: inline;
    margin-top: 10px;
    margin-left: 10px;
    }
    </style>"; // creates a div names $div

     

    The above should be regular raw HTML, not echoed with PHP.

     

    Also, it should look something like this

    <style type="text/css">
    div.imageClass {
    width: 162px;
    height: 121px;
    display: inline;
    margin-top: 10px;
    margin-left: 10px;
    float:left;
    }
    </style>;
    

     

    Then, in your loop, all you need to do is this

    echo "<div class='imageClass'>"; //display div named $div

  9. Since you want to capture the input of a dot (period) on-the-fly / live it is not considered a server side script. In other words.. PHP would have nothing to do with capturing the dot character as they type.

     

    Javascript is what you are looking for ... and jQuery is the best possible framework that I know of to implement your Javascript.

     

    Here is an example to get you started

    http://api.jquery.com/keypress/

  10. However, imploding an array into a delimited string is so simple...

     

    http://php.net/implode

    implode is what you are looking for, but like you've been advised on plenty of times so far, it is not the correct way to go and you will ultimately end up with deeper problems if you persist with the implode method.

     

    But like I have already learned from trial and error. You cannot teach trial and error, so go crazy and figure out the reason behind our advise yourself. Then you can come back and tell us, "You were right"

  11. There are few episodes in Workaholics.. that mention web design and even though the show has nothing to do with programming, it is totally worth a watch. In fact, I think I will watch an episode right now.

     

    -- "It isn't very often that you get a second chance at third love"

  12. The best I've seen that wasn't a documentary was Pirates of Silicon Valley which was a made-for-TV movie about Bill Gates and Steve Jobs.

    http://en.wikipedia.org/wiki/Pirates_of_Silicon_Valley

     

    Fun fact: the guy who voices Bender on Futurama (along with other cartoon roles) played Steve Ballmer in the movie. Inspired casting.

     

    Great movie that. I was going to suggest the same thing, but like Kevin already pointed out, it barely covers anything about programming at all. It is more about piracy, stealing ideas, trickery/treason, etcetera... and how it equates to being a successful business person.

     

    **I never knew that about the Bender/Balmer connection. Thanks for the trivia.

  13. In order to do the toggle from clicking outside the div, you will need a fixed position invisile overlay that covers the entire screen. So, whenever the login link is clicked, the overlay´s z-index is moved up above the rest of the page yet underneath your login/register boxes. This way you can have one single function to hide everything

     

    The overlay would have a width and a height of 100%, its position would be fixed, with no margins, borders, or anything else. You COULD if you wanted to, make its background gray with a 50 to 60 percent opacity. Either way, when it is all said and done you would have a jQuery function like this

     

    $("#overlay").click(function() {
        $(".login-form, .register-form").hide();
    });
    

     

    Or you could do it the risky way and hide upon the click of anything on the page, but you would have to list and rule out which elements should not trigger the hiding, like for instance, links, inputs, buttons, etcera, that are inside your login-form and register-form.

    $("*").click(function() {
        if($(this).parent().className != "login-form") {
               $(".login-form, .register-form").hide();
        }
    });
    

     

    Furthormore, when I googled your problem, the very first result gave me this

    http://stackoverflow.com/a/1403648/401299

     

    which is WAY better than my solution.

  14. PHP does not make queries, MySQL does.

     

    To achieve what you want you will need to use a join.

    "SELECT * FROM articles a
    JOIN categorys c ON a.profile = c.id
    ORDER BY a.id DESC LIMIT ".$from.", 20"

  15. You are not querying your SELECT statement. You are literally putting the SELECT query inside the INSERT query.

     

    $fuel_code = 'SELECT * FROM expense_categories WHERE type = $fuel_type'; 
    
    
    $sql="INSERT INTO expense_fuel (id, fuel_type, amount, month, day, year)
    VALUES
    ('$fuel_code', '$fuel_type', '$fuel_amount', '$fuel_month', '$fuel_day', '$fuel_year')";
    

     

    This will create a query that looks like this

    INSERT INTO expense_fuel (id, fuel_type, amount, month, day, year)
    VALUES
    ('SELECT * FROM expense_categories WHERE type = $fuel_type', '$fuel_type', '$fuel_amount', '$fuel_month', '$fuel_day', '$fuel_year')

     

    Can you explain again what exactly you are trying to do? Although I have pointed out a serious problem, I still cannot understand your purpose. If you want the value from a SELECT query to go into your INSERT query, then why are you SELECTing everything, that makes no sense unless the tables expense_fuel and expense_categories have the exact same columns....which I highly doubt.

     

     

    It would help you more than us tremendously if you post your database layout and some sample data.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.