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 17
  1. #1
    Join Date
    Dec 2007
    Posts
    1,683
    Tokens
    0

    Latest Awards:

    Default Spotlight script [SELECT ONLY VIA USERS IN DATABASE]

    Right, I was bored and got "inspired" by Jack's thread.. This collects the image from Habbo still, but spotlights a random Habbo inserted into the database table.

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

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

    $random rand(1$amount);

    $getusers mysql_query("SELECT * FROM `habbos` WHERE `id`='$random'");
    $showuser mysql_fetch_array($getusers);
    $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>';

    ?>
    MySQL Code:
    Code:
    CREATE TABLE IF NOT EXISTS `habbos` (
      `id` int(3) NOT NULL auto_increment,
      `habboname` varchar(30) NOT NULL,
      `habbohotel` varchar(30) NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
    If you wish to insert users, here's the SQL code;
    Code:
    INSERT INTO `habbos` (`id`, `habboname`, `habbohotel`) VALUES
    (1, 'Xedon', 'co.uk'),
    (2, 'Nooblah', 'co.uk');
    Like that..

    Hope this helps, I'd have made a inserter as well but I'm not sure if people would have wanted that, this is best for staff pages, like "Random staff".

    I'll make an inserter file if you request it.

    I know this is badly coded, but I made it in 10mins.

    Edit: This may show the same image twice, but after another refresh it shouldnt.
    Last edited by Independent; 22-07-2008 at 07:18 PM.

  2. #2
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Theres only one problem with your random.

    What if you have to delete an entry, that means the id's could be like:

    id | habbo
    1 | Habbo 1
    2 | Habbo 2
    4 | Habbo 3
    5 | Habbo 4
    7 | Habbo 5

    So if the random picks up id 3, there's no entry for it.

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

    Latest Awards:

    Default

    Quote Originally Posted by Jack120 View Post
    Theres only one problem with your random.

    What if you have to delete an entry, that means the id's could be like:

    id | habbo
    1 | Habbo 1
    2 | Habbo 2
    4 | Habbo 3
    5 | Habbo 4
    7 | Habbo 5

    So if the random picks up id 3, there's no entry for it.
    You could use mysql_affected_rows() to check if it exists, then if it doesn't choose another random one.
    Lets set the stage on fire, and hollywood will be jealous.

  4. #4
    Join Date
    Aug 2005
    Location
    London
    Posts
    9,773
    Tokens
    146

    Latest Awards:

    Default

    Wouldn't it just be easier to have the query as:
    PHP Code:
    $random mysql_query("SELECT habbonames FROM habbos ORDER BY RAND() LIMIT 1");
    $habbo mysql_fetch_array($random); 
    With the array variable $habbo[0] being the actual Habbo?

  5. #5
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    I was just about to post exactly the same thing ss.


    www.fragme.co = a project.

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

    Latest Awards:

    Default

    I was too.. LOL

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

    Latest Awards:

    Default

    Quote Originally Posted by --ss-- View Post
    Wouldn't it just be easier to have the query as:
    PHP Code:
    $random mysql_query("SELECT habbonames FROM habbos ORDER BY RAND() LIMIT 1");
    $habbo mysql_fetch_array($random); 
    With the array variable $habbo[0] being the actual Habbo?
    Im not sure im right, but when you use rand it makes a seprate temp table, which can slow down the execution time of a script if there are too many rows in the table.
    Lets set the stage on fire, and hollywood will be jealous.

  8. #8
    Join Date
    Aug 2005
    Location
    London
    Posts
    9,773
    Tokens
    146

    Latest Awards:

    Default

    Quote Originally Posted by Tom743 View Post
    Im not sure im right, but when you use rand it makes a seprate temp table, which can slow down the execution time of a script if there are too many rows in the table.
    Yep, you seem to be correct. But then again you'd have to have quite a large table for it to make much of an difference and seeing as it's going to be to show the name off a staff member or something it shouldn't have that many entries anyway .

  9. #9
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by Tom743 View Post
    Im not sure im right, but when you use rand it makes a seprate temp table, which can slow down the execution time of a script if there are too many rows in the table.
    Looks like I may have to redo our random spotlight. We have 3,374 entries

  10. #10
    Join Date
    Jul 2008
    Posts
    105
    Tokens
    0

    Default

    I think this is much more appropriate for a spotlight script

    http://clubhabboforum.net/showthread...=1#post1021573

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
  •