/    Sign up×
Community /Pin to ProfileBookmark

PHP High Low Game

I’m basicly making a high low game.

It generates a random number 1 – 10 then you guess if it will the next random number will will be higher or lower.

[code=php]<?
$page = $_GET[“g”];
switch($g)
{
case ‘h’:
echo ‘guesses next number will be higher’;
echo $number1;
break;
case ‘l’:
echo ‘guesses next number will be higher lower’;
break;
default:
$number1 = rand(1,10);
echo $number1;
break;
}
?><br>
<br>
<a href=”http://www.geek.cairns-hosting.com/highlow/highlow.php?g=h” target=”_self”>Higher</a> <a href=”http://www.geek.cairns-hosting.com/highlow/highlow.php?g=l” target=”_self”>Lower</a>
[/code]

The problem is when it goes to [url]http://www.geek.cairns-hosting.com/highlow/highlow.php?g=h[/url] or [url]http://www.geek.cairns-hosting.com/highlow/highlow.php?g=l[/url] The $number becomes nothing. It doesn’t remember it when it loads again.

Does anyone have a better way to do this?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@BeachSideJun 29.2005 — it should be $_GET['g'] with single quotes you have double quotes and also you aren't calling the variable $page in your switch...

it needs to be
[code=php]
<?
$page = $_GET['g'];
switch($page)
{
case 'h':
echo 'guesses next number will be higher';
echo $number1;
break;
case 'l':
echo 'guesses next number will be higher lower';
break;
default:
$number1 = rand(1,10);
echo $number1;
break;
}
?>
[/code]


Another thing to think about... If you plan on this running on any other server than your own you will want to consider using <?php ?> instead of short tags <? ?>
Copy linkTweet thisAlerts:
@NogDogJun 29.2005 — FYI, the type of quote (double or single) doesn't matter in this case for the array key - either designates it as a literal string and will work fine, the main difference being that double-quotes allow for variable interpolation.
Copy linkTweet thisAlerts:
@BeachSideJun 29.2005 — Yeah I guess I shouldn't have said 'should' I just like to see it that way (with single quotes) for consistancy's sake kinda like naming variables I hate to use single letters. You get a couple of hundred lines into some code and then have to figure out what something like $t is can be rather frustrating lol
×

Success!

Help @pixel-artist-2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...