Hello, I need to know whether conditional inclusion is possible in php. If not can anyone suggest a better method to so. This is what I am trying to do: if($page == "user_list") include("includes/user_list.php"); elseif($page == "adduser") include("includes/user.php"); PHP: Please help me, thanks in advance.
yes its possible, your in the right track, your code is good.. conditional statements for conditional method (if, else, elseif, do, while, foreach, switch, etc..)
Yeah the way you are suing code is right. There's nothing wrong in it. Keep your code more towards OO.
That code works. I sometimes don't understand why people ask questions like that rather than just trying it, which is faster than posting the question in a forum.
got the code. Thank You all. <?php // This is WRONG and will not work as desired. if ($condition) include $file; else include $other; // This is CORRECT. if ($condition) { include $file; } else { include $other; } ?> PHP:
It is only because that code didn't work. Check the above code for the difference. It is better try before you comment something. anyway thank You.
it is both correct, theres just no ':' try this one its the same if ($condition): include $file; elseif ($bar): include $other; endif;
The two different code samples you posted have identical effect. If you are getting different results then something else is going on.
Well may be, but digital point is my last resort for clearing my problems. Thank you all for helping me out.