[WTH] Programmer - If users online counter >= 10, display button on page

Discussion in 'PHP' started by rsanchez78118, Jul 16, 2009.

  1. #1
    I need code as follows:

    A counter that displays the number of users online. When the number reaches 10, I want it to trigger a javascript button (don't have it yet, but i will take care of that part) to come up so the users can press it. You can just echo "10 people are online" for now. I don't know if the page would have to refresh for the button to appear?

    So basically:
    If 10 people visit the page,
    then display javascript button

    If you know a better way of doing this, I am open to suggestions and comments.

    I know it may not be that hard, but I lack the programming knowledge.
    Can pay paypal. :cool:
     
    rsanchez78118, Jul 16, 2009 IP
  2. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'll be able to do this, please message me.
     
    matthewrobertbell, Jul 16, 2009 IP
  3. CuBz

    CuBz Peon

    Messages:
    117
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <?php
    $timenow=time();
    $select = mysql_query("SELECT * FROM table WHERE online > '$timenow' ORDER by id");
    
    $num = mysql_num_rows($select);
    
    if($num < 9){
    echo "$num";
    }
    elseif($num > 9){
    PUT JAVA CODE DOWN ERE
    }
    
    
    ?>
    PHP:
    I think thats right
     
    CuBz, Jul 16, 2009 IP
  4. rsanchez78118

    rsanchez78118 Peon

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thank you for your response cubz.
    but i don't understand what to do with that code. can you go into more detail?
    and how do i link it to the mysql database?

    Thanks :)
     
    rsanchez78118, Jul 16, 2009 IP
  5. CuBz

    CuBz Peon

    Messages:
    117
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    do you have msn? pm me with your email address and i'll help you out
     
    CuBz, Jul 16, 2009 IP
  6. porntorch

    porntorch Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you're going to do it like that, you may as well increase the efficiency. What's the point in selecting all the data if all you want is a count?

    Change it to:
    <?php
    $timenow=time();
    $num = mysql_query("SELECT COUNT(id) FROM table WHERE online > '$timenow'");
    
    if($num < 9){
    echo "$num";
    }
    elseif($num > 9){
    PUT JAVA CODE DOWN ERE
    }
    
    
    ?>
    PHP:
     
    porntorch, Jul 19, 2009 IP