Higher/Lower Script

By F*U*R*B*Y* on May 11, 2008

Just a pretty simple Higher/Lower Script

<style type="text/css">
    table {

        width: 125px;

    }

    td {

        padding: 1px;
        border: 1px solid #666666;
        text-align: center;

    }
</style>
<?php

session_start();

function Start_Again() {
    $number = rand(1,100);
    $_SESSION['higherlower'] = $number;
    echo "Select a Number below.";
    Display_Form();
}

function Display_Form() {
    echo "<table>";
    for ($num=1;$num < 101;$num++) {
        if (!preg_match("/(.*?)0/", $num)) { echo "<td><a href=\"".$PHP_SELF."?number=".$num."\">".$num."</td>"; }
        else { echo "<td><a href=\"".$PHP_SELF."?number=".$num."\">".$num."</td></tr><tr>"; }
    }
    echo "</table>";
}

if (isset($_GET['number'])) {
    $User_Number = $_GET['number'];
    $Actual_Number = $_SESSION['higherlower'];

    if ($User_Number < $Actual_Number) { echo "Higher"; Display_Form(); }
    elseif ($User_Number > $Actual_Number) { echo "Lower"; Display_Form(); }
    elseif ($User_Number == $Actual_Number) { echo "Bingo, Correct Guess!<br>"; Start_Again(); }

}elseif (!isset($_POST['higherlower'])) { Start_Again(); }

?>

Comments

Sign in to comment.
Jonesy44   -  May 11, 2008

lol, koolio ;D
There are so many functions in PHP, and let\'s be honest, the syntax help on the main website is a load of crap, italics bold, just gimme the feckin stuff !

 Respond  
F*U*R*B*Y*   -  May 11, 2008

yeah i didn\'t know how to like make it check if it was *0 so i just did a preg_match, if i can think up another way, will change it ;) but it works

 Respond  
Jonesy44   -  May 11, 2008

Good stuff FURBY* ;D

preg_match function here makes no sense to me :P
I seem to remember using it a while back for a wildcard kinda thing.

Anyways, gj :P

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.