Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

Thread: simple random problem

1. simple random problem

Here is my code, its simple, I want php to generate a random number, then if its inbetween 1-5 echo a certain thing, or else if its 6-10 echo something else.

PHP Code:
``` <? \$rand = rand(1,10) if(\$rand == 1 || 2 || 3 || 4 || 5) { echo "<h1>one thing</h1>"; } if(\$rand == 6 || 7 || 8 || 9 || 10) { echo "<h1>other thing</h1>"; } ?> ```
all that happens now is a blank page
thanks i'm dumb

• <?
\$rand = rand(1,10);
if(\$rand == 1 || 2 || 3 || 4 || 5)
{
echo "<h1>one thing</h1>";
}

if(\$rand == 6 || 7 || 8 || 9 || 10)
{
echo "<h1>other thing</h1>";
}
?>
You missed a semi colon. But try this. This code can probably be optimized, though.

PHP Code:
``` <?php\$rand = rand(1,10);if(\$rand >= 1 && \$rand <= 5){ // If \$rand is greater than or equal to 1 AND less than or equal to 5    echo "Numbers 1 - 5!";}if(\$rand >= 6 && \$rand <= 10){ // If \$rand is greater than or equal to 6 AND less than or equal to 10    echo "Numbers 6 - 10!";}?> ```

• Users who have thanked [vengeance] for this post:

firecat318 (09-15-2009)

• thanks it worked

•

Posting Permissions

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