Thread: Variable Prints

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Randolph, NJ
    Posts
    36
    Rep Power
    15
    Ok. I have a form that is a pull down menu and has the values of 1,2,3,4 or 5. This script, the user ranks certain things. So if the user selects 3, then in the output, it prints a little star image 3 times. How can I write this without having to write an if statement and 4 more elseif's? Thank you, any help is appreciated.

    ------------------
    ================
    -Khill, www.tsrealm.com
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    51
    Rep Power
    15
    you can use the switch statement such as the following below:

    switch($string)
    {
    case "bob":
    print"hi bob";
    break;
    case "sally":
    print "hi sally";
    break;
    default:
    print "hi there";
    }


    ------------------

    Yanik!
    Edmonton, AB
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Pune, Maharashtra, India
    Posts
    86
    Rep Power
    15
    Let the variable $num contains the rank the user has given then u can proceed with the following two things:
    1 st Method
    for($a=1;$a<=$num;$a++)
    {
    echo ("*");//'*' imples the star
    }
    2 nd Method:
    switch($num)
    {
    case 1:
    echo ("*");

    case2:
    echo ("**");

    " " "
    }
    And So on..
    Then Bye and ENJOY!

Similar Threads

  1. Replies: 4
    Last Post: February 13th, 2004, 04:31 PM
  2. A variable $_POST variable?
    By CLuver in forum PHP Development
    Replies: 0
    Last Post: February 11th, 2004, 01:55 AM
  3. How to read multiple line text file into a variable
    By gatewaycityca in forum Visual Basic Programming
    Replies: 4
    Last Post: January 29th, 2004, 01:26 PM
  4. Using the echo tag to integrate a PHP variable into Javascript
    By spayce_girl in forum JavaScript Development
    Replies: 5
    Last Post: December 27th, 2003, 06:42 PM
  5. Replies: 5
    Last Post: November 16th, 2003, 12:31 PM

IMN logo majestic logo threadwatch logo seochat tools logo