Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7185299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:23:11+00:00 2026-05-28T18:23:11+00:00

I’m trying to declare a variable depending on what the number is. I’m trying

  • 0

I’m trying to declare a variable depending on what the number is.

I’m trying to do “if $var is less than [amount] and greater than [amount] var = blah elseif $var is less than [amount] and greater than [amount] var = blah” etc. Here is my code:

$randomNumber = rand(1, $funnyPicsHigh);

if($randomNumber > 0 && $randomNumber < 2001){
$directory_to_use = 1;

}elseif($randomNumber > 2000 && $randomNumber < 4001){
$directory_to_use = 2;

}elseif($randomNumber > 4000 && $randomNumber < 6001){
$directory_to_use = 3;

}elseif($randomNumber > 6000 && $randomNumber < 8001){
$directory_to_use = 4;

}elseif($randomNumber > 8000 && $randomNumber < 10001){
$directory_to_use = 5;

}elseif($randomNumber > 10000 && $randomNumber < 12001){
$directory_to_use = 6;

}elseif($randomNumber > 10000 && $randomNumber < 12001){
$directory_to_use = 7;

}elseif($randomNumber > 12000 && $randomNumber < 14001){
$directory_to_use = 8;

}elseif($randomNumber > 14000 && $randomNumber < 16001){
$directory_to_use = 9;

}elseif($randomNumber > 16000 && $randomNumber < 18001){
$directory_to_use = 10;

}elseif($randomNumber > 18000 && $randomNumber < 20001){
$directory_to_use = 11;

}

I started out using if then elseif for everything, I then changed it so it is >= and <=, still didn’t work, then I tried putting ” ” before and after my numbers which is what you see now, still didn’t work.

The random number executes just fine, but it seems to pick a random directory. I’ll refresh the page and it picks 5 for the directory to use. I refresh it again and it picks 1, then picks 1, then picks 3. It seems to just randomly pick a number.

What am I doing wrong?


FIGURED it out, thank you everyone. It was due to my logic not the code provided. Talking out loud trying to explain my problem is what helped me so thanks. If wondering what the working code is, it’s here:
http://pastebin.com/en2sc3HC

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:23:12+00:00Added an answer on May 28, 2026 at 6:23 pm

    Your code can be significantly simplified

    $directory_to_use = ceil(rand(1, $funnyPicsHigh) / 2000);
    

    if that is a typo

    }elseif($randomNumber > 10000 && $randomNumber < 12001){
    $directory_to_use = 6;
    
    }elseif($randomNumber > 10000 && $randomNumber < 12001){
    $directory_to_use = 7;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.