Results 1 to 9 of 9
  1. #1
    Grandma broke her coccyx! Uncle Rico's Avatar
    Join Date
    May 8th, 2007
    Location
    North Carolina
    Posts
    2,238
    Change to Specific Set of Values Upon Refresh
    I can't use rand() because I want to set a variable based on 2 or 3 specific values. For example, I would like to set $BUTTS to the value of '5', '46', or '100' as an eample. The rand won't work because I don't want every value between 5 and 100.

    Something like this. Any idea how this could be accomplished in php?

    $BUTTS = 5
    ..page refresh..
    $BUTTS = 100
    ..page refresh..
    $BUTTS = 46
    ..page refresh..
    $BUTTS = 100
    ..page refresh..
    $BUTTS = 5

  2. #2
    ABW Ambassador Daniel M. Clark's Avatar
    Join Date
    January 7th, 2006
    Location
    Houston, TX
    Posts
    2,082
    I'm still at the beginner level with PHP, but my first thought was to define ranges, and then set $BUTTS to a value based on the range returned by rand(). So, say, get a rand() value between 1 and 100, and:

    if ($value >= 1 && $value <=33)
    $BUTTS = 5;

    if ($value >= 34 && $value <=66)
    $BUTTS = 46

    if ($value >= 67 && $value <=100)
    $BUTTS = 100

    Would that work? There's probably a function that will choose between given values, maybe using an array, but I don't know what it is

  3. #3
    Moderator MichaelColey's Avatar
    Join Date
    January 18th, 2005
    Location
    Mansfield, TX
    Posts
    16,232
    Have you tried RAND(5,100)? That will return a random number between 5 and 100 (inclusive).
    Michael Coley
    Amazing-Bargains.com
     Affiliate Tips | Merchant Best Practices | Affiliate Friendly? | Couponing | CPA Networks? | ABW Tips | Activating Affiliates
    "Education is the most powerful weapon which you can use to change the world." Nelson Mandela

  4. #4
    Grandma broke her coccyx! Uncle Rico's Avatar
    Join Date
    May 8th, 2007
    Location
    North Carolina
    Posts
    2,238
    But I don't want every number between 5 and 100.

  5. #5
    ABW Ambassador Daniel M. Clark's Avatar
    Join Date
    January 7th, 2006
    Location
    Houston, TX
    Posts
    2,082
    How about this - you can do rand(1,x), where x is the number of choices you want. Then, you can do a switch based on the numbers returned. That would probably be easier than what I first posted.

  6. #6
    Grandma broke her coccyx! Uncle Rico's Avatar
    Join Date
    May 8th, 2007
    Location
    North Carolina
    Posts
    2,238
    Ok, I got it working as needed. Thanks.

  7. #7
    Believe knight01's Avatar
    Join Date
    August 14th, 2006
    Location
    Dayton, Ohio
    Posts
    1,815
    You need to set $BUTTS as an array.

    $range=var(5,46,100)
    $BUTTS=$array()


    Something along those lines. I'm not proficient enough at php to code it from memory but that should be enough to search some of the php forums and find a sample you can use.
    Someday starts today
    Military Discounts

  8. #8
    Moderator MichaelColey's Avatar
    Join Date
    January 18th, 2005
    Location
    Mansfield, TX
    Posts
    16,232
    My bad. I totally missed the "don't" in your original post.
    Michael Coley
    Amazing-Bargains.com
     Affiliate Tips | Merchant Best Practices | Affiliate Friendly? | Couponing | CPA Networks? | ABW Tips | Activating Affiliates
    "Education is the most powerful weapon which you can use to change the world." Nelson Mandela

  9. #9
    Grandma broke her coccyx! Uncle Rico's Avatar
    Join Date
    May 8th, 2007
    Location
    North Carolina
    Posts
    2,238
    Quote Originally Posted by MichaelColey
    My bad. I totally missed the "don't" in your original post.
    It's snow problem.

  10. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. How do you send SID values?
    By dealpigg in forum Commission Junction - CJ
    Replies: 5
    Last Post: July 7th, 2009, 02:29 AM
  2. Matching Specific Sales To Specific Clicks
    By blitwin in forum Midnight Cafe'
    Replies: 1
    Last Post: May 7th, 2008, 07:40 PM
  3. Domain Name Values - Part II
    By cera in forum Domains & Hosting
    Replies: 3
    Last Post: July 21st, 2005, 03:56 PM
  4. Domain name values?
    By cera in forum Domains & Hosting
    Replies: 13
    Last Post: June 9th, 2005, 10:05 PM
  5. Comparing Two WM-Field Values?
    By huhu in forum WebMerge (Fourthworld.com)
    Replies: 5
    Last Post: September 11th, 2003, 06:40 PM

Posting Permissions

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