Page 1 of 1

[Solved]How to display something by checking something.

Posted: Mon Jun 16, 2008 10:41 am
by ignas2526
Hello, im new here and new in php coding,
I don't know how to call thing, i want to create file from who will be possible to control what to show and what to hide. The thing i want is to add file in same directory there is main file, lets say control.php, and to main file add code what will be something like: if in control.php showing image1 and image2 is true, wan show image1 and image2, else show nothing. Ore if in control.php show code3 'code show = 3', wan show not first not second but third code only.
Do anyone have idea how to do it, ore where i can find example code, ore where i can find something like whys :?:
Thanks for help.

Re: How to display something by checking something.

Posted: Mon Jun 16, 2008 12:10 pm
by califdon
It is difficult to answer such a broad question. If you have done any programming, in any language, you will be familiar with "conditional statements" such as

Code: Select all

IF ( /true or false condition/ ) { 
    / do something /
} ELSE {
   / do something else /
}
But there is no general answer to how to code either the condition or the actions. That depends on the details of what your script is doing and what variables you have. In case you have no prior programming experience, then you need to study basic programming, which you will not be able to learn in an online forum, such as here. This forum is for specific questions and problems.

Good luck learning PHP. I suggest that you start with reading tutorials, such as at http://w3schools.com.

Re: How to display something by checking something.

Posted: Mon Jun 16, 2008 5:13 pm
by ignas2526
Thanks,
i now figured out how to:
here is code:
For two:

Code: Select all

<?php
$numbers = 2;
 
    if ($numbers == 1) {
    echo "its 1 now";
    } else {
    if ($numbers == 2) 
    echo "its 2...";
    }
?>
For three:

Code: Select all

<?php
$numbers = 3;
 
    if ($numbers == 1) {
    echo "its 1 now";
    } elseif ($numbers == 2) {
    echo "its 2...";
    }
    elseif ($numbers == 3) {
    echo "its 3!";
    }
?>
One bad is what there no way to use words :(