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 12
  1. #1
    Join Date
    Apr 2006
    Location
    Leamington Spa
    Posts
    1,375
    Tokens
    72

    Latest Awards:

    Default [Tutorial] PHP ~ Love Calculator

    These things are always popular with everyone, so I decided to code one to try to make my hunger pains go away... This uses a the rand(); function and echo's an appropriate message to their number.
    It's entriely self contained.
    PHP Code:
    <?php
    //LOVE CALCULATOR!!!
    echo("
    <font size=\"2\" face=\"Verdana\">
    <form method=\"POST\">
    Your Name: <input type=\"text\" name=\"name1\">
    <br />
    Crushes Name: <input type=\"text\" name=\"name2\">
    <br />
    <input type=\"submit\" value=\"Calculate\">
    </form>
    "
    );
    //Woo. So now we choose what to do if the forms sent.
    $name1 $_POST['name1']; // The "Your Name:" variable.
    $name2 $_POST['name2']; // The "Crushes Name:" variable.
    if(!$name1){ exit(); }
    $rand rand(1,99); // Uses the rand(); function in PHP to make a number between 1 and 99
    echo("<b>$name1</b> and <b>$name2</b>'s love rating is <b>$rand</b>.<br />"); // Result. We've echoed it. Now we'll do a "Cupids Comment" thing.
    if($rand <= "20"){
    echo(
    "Cupids Comment: Face it, it's not gonna work out between the two of you!");
    }
    if(
    $rand <= "40" && $rand >= "21"){
    echo(
    "Cupids Comment: There could be love between you two, but then again, maybe not.");
    }
    if(
    $rand <= "60" && $rand >= "41"){
    echo(
    "Cupids Comment: Try it and see, there's about a 50/50 chance.");
    }
    if(
    $rand <= "80" && $rand >= "61"){
    echo(
    "It's likely, the chances of the spark going are preety slim.");
     }
    if(
    $rand <= "99" && $rand >= "81"){
    echo(
    "Cupids Comment: There's almost definiatley love there! Go ahead. Your not gonna be heartbroken.");
    }
    echo(
    "</font>");
    ?>
    Fixed all errors, see it in action at http://tazroger.net/edd/lovecalc.php.
    Last edited by lolwut; 07-10-2007 at 03:38 PM.
    i've been here for over 8 years and i don't know why

  2. #2
    Join Date
    Apr 2006
    Location
    Leamington Spa
    Posts
    1,375
    Tokens
    72

    Latest Awards:

    Default

    Wouldn't let me edit;
    Better code, fixed >= errors;
    PHP Code:
    <?php
    echo("<font face=\"Verdana\" size=\"2\">");
    //LOVE CALCULATOR!!!
    if(!$_POST['calc']){
    echo(
    "
    <form method=\"POST\">
    Your Name: <input type=\"text\" name=\"name1\">
    <br />
    Crushes Name: <input type=\"text\" name=\"name2\">
    <br />
    <input type=\"submit\" value=\"Calculate\" name=\"calc\">
    </form>
    "
    );
    }else{
    //Woo. So now we choose what to do if the forms sent.
    $name1 $_POST['name1']; // The "Your Name:" variable.
    $name2 $_POST['name2']; // The "Crushes Name:" variable.
    if(!$name1){ echo("Please enter your name!"); exit(); } // If they didn't post their name, reject the form.
    if(!$name2){ echo("Please enter your crushes name!"); exit(); } // If they didn't post their crushes name, reject the form.
    $rand rand(1,99); // Uses the rand(); function in PHP to make a number between 1 and 99
    echo("<b>$name1</b> and <b>$name2</b>'s love rating is <b>$rand</b>.<br />"); // Result. We've echoed it. Now we'll do a "Cupids Comment" thing.
    if($rand <= "20"){
    echo(
    "Cupids Comment: Face it, it's not gonna work out between the two of you!"); // Message if love rating is under 20.
    }
    if(
    $rand <= "40" && $rand >= "21"){
    echo(
    "Cupids Comment: There could be love between you two, but then again, maybe not."); // Message if love rating is under 40.
    }
    if(
    $rand <= "60" && $rand >= "41"){
    echo(
    "Cupids Comment: Try it and see, there's about a 50/50 chance."); // Message if love rating is under 60.
    }
    if(
    $rand <= "80" && $rand >= "61"){
    echo(
    "It's likely, the chances of the spark going are pretty slim."); // Message if love rating is under 80.
     
    }
    if(
    $rand <= "99" && $rand >= "81"){
    echo(
    "Cupids Comment: There's almost definiatley love there! Go ahead. Your not gonna be heartbroken.");
    }
    $referer $_SERVER['HTTP_REFERER'];
    echo(
    "<br /><a href=\"$referer\">Try Again?</a>"); // Shows Try Again message.
    }
    echo(
    "</font>");
    ?>
    i've been here for over 8 years and i don't know why

  3. #3
    Join Date
    Jul 2005
    Posts
    1,653
    Tokens
    50

    Latest Awards:

    Default

    Learn to indent your code.

  4. #4
    Join Date
    Jul 2007
    Location
    Swindon
    Posts
    990
    Tokens
    125

    Default

    Well its different and definetly a good try. I may use it on my site if i have random 'generators' as such. would rep you if I could.

  5. #5
    Join Date
    Jun 2006
    Location
    Manchester
    Posts
    56
    Tokens
    0

    Default

    Quote Originally Posted by RYANNNNN View Post
    Learn to indent your code.
    Quoted for truth.

  6. #6
    Join Date
    Apr 2006
    Location
    Leamington Spa
    Posts
    1,375
    Tokens
    72

    Latest Awards:

    Default

    Thanks all, indentings hard as hell in a web editor, unless you wanna use spaces. I prefer tabs.
    i've been here for over 8 years and i don't know why

  7. #7
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    3,285
    Tokens
    0

    Latest Awards:

    Default

    I was gonna make one of these too, I'll indent it for you (maybe)



    i used to be NintendoNews. visit my blog or add me on twitter.
    need help with vista? i am a microsoft certified technology specialist in configuring windows vista and connected home integrator.. pm me for help!


    "I am the way, the truth, and the life. No one comes to the Father except through me"
    John 14:6 (NIV)


  8. #8
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?php
    if ($_GET['action'] == "submit")
    {

        
    $name1 $_POST['name1'];
        
    $name2 $_POST['name2'];

        if (
    $name1 == null)
        {
            echo 
    "Please enter your name!";
            exit;
        }
        if (
    $name2 == null)
        {
            echo 
    "Please enter your crushes name!";
            exit;
        }

        
    $rand rand(199);
        echo 
    "<strong>$name1</strong> and <strong>$name2</strong>'s love rating is <strong>$rand</strong>.<br />";

        if (
    $rand <= "20")
        {
            echo (
    "Cupids Comment: Face it, it's not gonna work out between the two of you!"); // Message if love rating is under 20.
        
    }
        if (
    $rand <= "40" && $rand >= "21")
        {
            echo (
    "Cupids Comment: There could be love between you two, but then again, maybe not."); // Message if love rating is under 40.
        
    }
        if (
    $rand <= "60" && $rand >= "41")
        {
            echo (
    "Cupids Comment: Try it and see, there's about a 50/50 chance."); // Message if love rating is under 60.
        
    }
        if (
    $rand <= "80" && $rand >= "61")
        {
            echo (
    "It's likely, the chances of the spark going are pretty slim."); // Message if love rating is under 80.
        
    }
        if (
    $rand <= "99" && $rand >= "81")
        {
            echo (
    "Cupids Comment: There's almost definiatley love there! Go ahead. Your not gonna be heartbroken.");
        }
        
    $referer $_SERVER['HTTP_REFERER'];
        echo 
    "<br /><a href=\"$referer\">Try Again?</a>"// Shows Try Again message.
        
    exit;
    }
    ?> 
    <font face="Verdana" size="2">
    <form method="post" action="?action=submit">
    Your Name: <input type="text" name="name1">
    <br />
    Crushes Name: <input type="text" name="name2">
    <br />
    <input type="submit" value="Calculate" name="calc">
    </form>
    </font>
    try that.

  9. #9
    Join Date
    Jul 2007
    Location
    Swindon
    Posts
    990
    Tokens
    125

    Default

    Sounds stupid but what does indent mean:S

  10. #10
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Eccentric View Post
    Sounds stupid but what does indent mean:S
    From this:

    PHP Code:
    <?php
    $name 
    "bob";
    if(
    $name == "bob") {
    echo 
    "hey";
    }else{
    echo 
    "bye";    
    }
    ?>
    to

    PHP Code:
    <?php
    $name 
    "bob";
    if (
    $name == "bob")
    {
        echo 
    "hey";
    }
    else
    {
        echo 
    "bye";
    }
    ?>

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
  •