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 2 of 2 FirstFirst 12
Results 11 to 17 of 17
  1. #11
    Join Date
    Dec 2007
    Posts
    1,683
    Tokens
    0

    Latest Awards:

    Default

    Thanks for your help.

    PHP Code:
    <?php
    // MySQL Connect code.

    $grab mysql_query("select * from `habbos`");
    $amount mysql_num_rows($grab);

    $random rand(1$amount);

    $random mysql_query("SELECT habbonames FROM habbos ORDER BY RAND() LIMIT 1");
    $showuser mysql_fetch_array($random);  
    $showusername $showuser['username'];

    echo 
    '<img border="0" src="http://www.habbo.' $showuser['habbohotel'] . '/habbo-imaging/avatarimage?user='$showuser['habboname'] .'&action=&direction=4&head_direction=3&gesture=sml&size=l&img_format=png"><br />Hello, '.$showuser['habboname'] .' plays Habbo.' $showuser['habbohotel'] . '</a>';

    ?>
    +REP for trying to help, which is everyone.. but shane (I think that's his name) got there first

    Query is *bobba*'d, I'll fix tomorrow morning.. I'm going to bed, night habboxforum
    Last edited by Independent; 22-07-2008 at 11:17 PM.

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

    Latest Awards:

    Default

    Quote Originally Posted by Independent View Post
    Thanks for your help.

    PHP Code:
    <?php
    // MySQL Connect code.

    $grab mysql_query("select * from `habbos`");
    $amount mysql_num_rows($grab);

    $random rand(1$amount);

    $random mysql_query("SELECT habbonames FROM habbos ORDER BY RAND() LIMIT 1");
    $showuser mysql_fetch_array($random);  
    $showusername $showuser['username'];

    echo 
    '<img border="0" src="http://www.habbo.' $showuser['habbohotel'] . '/habbo-imaging/avatarimage?user='$showuser['habboname'] .'&action=&direction=4&head_direction=3&gesture=sml&size=l&img_format=png"><br />Hello, '.$showuser['habboname'] .' plays Habbo.' $showuser['habbohotel'] . '</a>';

    ?>
    +REP for trying to help, which is everyone.. but shane (I think that's his name) got there first

    Query is *bobba*'d, I'll fix tomorrow morning.. I'm going to bed, night habboxforum

    For Jack that will still take a long time to execute, i would do;

    PHP Code:
    $ammount mysql_query "SELECT * FROM habbos" );
    $ammount mysql_affected_rows ();
    $randomnumber rand "1"$ammount );
    $mysql mysql_query "SELECT * FROM habbos WHERE id = '" $randomnumber );
    $showuser mysql_fetch_array $mysql );  

    echo 
    '<img border="0" src="http://www.habbo.' $showuser['habbohotel'] . '/habbo-imaging/avatarimage?user='$showuser['habboname'] .'&action=&direction=4&head_direction=3&gesture=sml&size=l&img_format=png"><br />Hello, '.$showuser['habboname'] .' plays Habbo.' $showuser['habbohotel'] . '</a>'
    Lets set the stage on fire, and hollywood will be jealous.

  3. #13
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    You may be better using the MySQL rand function rather than the PHP function

    Would be less code, worth a try...

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

    Latest Awards:

    Default

    If you use Mysql rand its slower to execute.
    Lets set the stage on fire, and hollywood will be jealous.

  5. #15
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    The first way is actually better if you have a larger database, RAND is slow on larger rowsets.

    It only returns ad hoc random results anyway.

  6. #16
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    Well if you wanted to remove one of the Habbos, and didnt replace it with the same id - it would be not found...

  7. #17
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Well yeah, that is using the first method with auto increment.

    You should be able to use RAND() just fine here without it slowing down, but on bigger applications.. no.

Page 2 of 2 FirstFirst 12

Posting Permissions

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