SitePoint Sponsor

User Tag List

Results 1 to 25 of 25

Thread: Members per day

  1. #1
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Members per day

    Okay.

    I'm trying to output in my Admin section the number of new members registered per day.

    I have launch_date as a DATE field in the database

    And I have a table for cms_users.

    What I think I have to do is to count the current number of members. But then how do I calculate how many have registered per day?

    Thanks!

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here it goes:
    PHP Code:
    <?php
    $today 
    date("Y-m-d");
    $newusers mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM tbl WHERE regdate='$today'"));
    $newusers $newusers[0];
    echo 
    "Total $newusers joined today";
    ?>
    I think you use 0000-00-00 for date?

  3. #3
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    launch_date was the date of the site launch?
    if so why not have a date the member registered?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #4
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    why not have a date the member registered?
    I do have that.

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    thought so! why not count the number of registrations for the days? or am I missing something and confusing myself!

    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm. I think perhaps I didn't make my situation clear. What I want is;

    13.8 members per day

    Which would be a calculation of

    days site has been active (current date - launch date) / number of members

    I think!

    Just not sure how to code it. Rokas if you get anywhere please reply! Thanks.

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhh!
    PHP Code:
    $q=mysql_query("SELECT DATEDIFF(NOW(), launch_date) as dayspassed from table");
    $r mysql_fetch_assoc($q);
    $regperday $r['dayspassed']/$total_members
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now i understood
    hmm well then it would way easier to use unix timestamp(seconds since 1970... http://lt.php.net/manual/en/function.time.php)

    If with timestamp then
    PHP Code:
    <?php
    $days 
    = (time() - $launch_time)/86400;
    $perday $users $days;
    ?>
    And retrieving information from db isnt that hard
    Oh well spikez already has a better way

  9. #9
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Um when you start a board, store the Unix timestamp of when the board was started and then just divide by the number of seconds in the day.

  10. #10
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys,

    Spikez : I receive the following error

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in .............

    I have this code

    PHP Code:
    $q=mysql_query("SELECT DATEDIFF(NOW(), launch_date) as dayspassed FROM cms_config");
    $r mysql_fetch_assoc($q); 

  11. #11
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure why you are doing it that way. Why not just store in a separate table a value that is the unix timestamp of the time when the board started?

    Code:
    $g="SELECT startime from timestart";
    $g=mysql_query($g);
    $g=mysql_fetch_array($g);
    $nowtime=date("U");
    $numdays=($nowtime-$g)/(3600*24);
    $memperday=$nummembers/$numdays;

  12. #12
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay ArchBob, I took your advice and changed to a unix timestamp.

    With the code, I get the error
    Fatal error: Unsupported operand types


    Here's my code

    PHP Code:
    $users mysql_query("SELECT COUNT(*) FROM cms_users");
                    
    $nummembers mysql_result($users0);
                      
                     
    $g="SELECT launch_date FROM cms_config";
                    
    $g=mysql_query($g);
                    
    $g=mysql_fetch_array($g);
                    
    $nowtime=date("U");
                    
    $numdays=($nowtime-$g)/(3600*24);
                    
    $memperday=$nummembers/$numdays;
                    
                    echo 
    '<font color ="#FF3300">' $memperday '</font>' 

  13. #13
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $users 
    mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM cms_users"));
    $users $users[0];
    extract(mysql_fetch_assoc(mysql_query("SELECT launch_date FROM cms_config")));
    $days = (time() - $launch_date)/86400;
    $perday $users $days;
    ?>
    Just make sure queries are correct(try running such queries in phpmyadmin or whatever u use)

  14. #14
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    It comes up as 0.0028125644408685

    Which is totally incorrect. The launch date was 2 weeks past, and there are twenty members.

    20/14 != 0.0028125644408685


  15. #15
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Print out $users and $days and see what values they are. Its probably one of those numbers, if its the time function thats messing up, try replacing it with date("U");

  16. #16
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Days is coming up as 7111, so this is where we are going wrong..Also changing the time function makes no difference.

  17. #17
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any ideas?

  18. #18
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Slight error in ArchBob's code I think ($g is an array, right? so):

    PHP Code:
    $g="SELECT startime from timestart";
    $g=mysql_query($g);
    $g=mysql_fetch_array($g);
    $nowtime=date("U");
    $numdays=($nowtime-$g['startime'])/(3600*24);
    $memperday=$nummembers/$numdays

  19. #19
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $users 
    mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM cms_users"));
    $users $users[0];
    extract(mysql_fetch_assoc(mysql_query("SELECT launch_date FROM cms_config")));
    echo 
    date("Y-m-d"$launch_date);
    $days = (time() - $launch_date)/86400;
    $perday $users $days;
    ?>
    check if echoed date is correct. Everything else is correct in this code, except for data taken from database(users number and timestamp)..

  20. #20
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    It is still coming up as 0.0029 though..

    My launch_date is stored as 0506201354
    The date appears as 1120655128

  21. #21
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rokas : The echoed date is 1986-01-15

  22. #22
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://lt.php.net/manual/en/function.mktime.php
    use this function to set the correct time
    2005-06-22 00:00:00 would be mktime(0,0,0,6,22,2005)
    mktime(hour,min,sec,mon,day,year)

  23. #23
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks man. That works.

    It's weird though, I can't seem to store the unix time in the database. Oh well, using your way works just as well anyway. Thanks again.

  24. #24
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u can try using varchar or int as field type

  25. #25
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to store the launch date as time() also. You can't use like a datetime field or something.


Bookmarks

Posting Permissions

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