Web Analytics Made Easy -
StatCounter else function - CodingForum

Announcement

Collapse
No announcement yet.

else function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • else function

    is it possible to have more than one if, one elseif, and one else in a script - can you have more than three functions like this in one statement?

    thanks
    Mike

  • #2
    Huh?

    I'm not sure I understand, but this is valid PHP if it means anything:

    PHP Code:
    if(true) {
     if(
    true) {
      ...
     }
     else if(
    true) {
      ...
      if(
    true) {
       ...
      else {
       ...
      }
     }
     else if(
    true) {
      ...
     }
    }
    else {
     ...

    The combinations are infinite. An if doesn't need an else, or an else if or anything; they are optional.

    Hope that helps,
    Sadiq.

    Comment


    • #3
      my script is below:

      PHP Code:
       <?php

      if ($_GET["name"] == comp){
          echo 
      "<img src=\"pics/1.gif\" align=texttop>";
      }

      elseif (
      $_GET["name"] == lap){
          echo 
      "<img src=\"pics/2.gif\" align=texttop>";
      }

      else{
          echo 
      "Please enter a valid place";
          }
      ?>
      i currently have an if,else and elseif but if i put in more than one i am getting errors - is there a way to do this and give more option for the script?
      Mike

      Comment


      • #4
        its working now - thanks for help
        Mike

        Comment


        • #5
          In situations like this you may want to consider using the switch statement, which is similar to a series of IF statements on the same expression:

          PHP Code:
          switch ($_GET["name"]) {
          case 
          "comp":
             
          $pic=1;
             break;
          case 
          "lap":
             
          $pic=2;
             break;
          default:
             
          $pic="defaultimage";
          }

          echo 
          "<img src=\"pics/$pic.gif\" align=texttop>"

          Comment

          Working...
          X