nathanmaxsonadil Posted August 24, 2007 Share Posted August 24, 2007 I was wondering how may else if's I'm allowed to have or can i have unlimted? Quote Link to comment https://forums.phpfreaks.com/topic/66423-how-may-else-ifs-are-you-allowed-to-have/ Share on other sites More sharing options...
akitchin Posted August 24, 2007 Share Posted August 24, 2007 it will keep going until the end of the block, so in brief, infinitely many. if you have a large number of conditionals, however, i would suggest migrating to a switch(){} block, as it's somewhat easier to look at. Quote Link to comment https://forums.phpfreaks.com/topic/66423-how-may-else-ifs-are-you-allowed-to-have/#findComment-332477 Share on other sites More sharing options...
Fadion Posted August 24, 2007 Share Posted August 24, 2007 Guess u can have as much as u like, but i wonder if u'll need so much. Quote Link to comment https://forums.phpfreaks.com/topic/66423-how-may-else-ifs-are-you-allowed-to-have/#findComment-332479 Share on other sites More sharing options...
teng84 Posted August 24, 2007 Share Posted August 24, 2007 in some case like of your will be using a fix value to be conditioned like string or number you can use the loop or switch like what akitchin said something like for($x=0;$x<=100;$x++) { if($x==100) echo teng; } as you can see you dont have to have hundreds of lines to complete the test Quote Link to comment https://forums.phpfreaks.com/topic/66423-how-may-else-ifs-are-you-allowed-to-have/#findComment-332485 Share on other sites More sharing options...
nathanmaxsonadil Posted August 24, 2007 Author Share Posted August 24, 2007 my code is like this if($_SESSION['loggedin'] == true) { if($variable == function($varible)) { //do something }else if(function($variable) !== "" && $varible == "true") { //do somthing }else if(isset($varible) && $varible == 1) { //do somthing if (mysql_num_rows($result) == 0) { //do somthing }else //do somthing } }else if(isset($varible2) && $varible2 == '1') { //do somthing if(mysql_num_rows($result) == 1) { do somthing }else if(mysql_num_rows($result) == 0) { //do somthing }else { //do somthing if logged in but nothing matches above } }else { //do somthing if not logged in } however this code just display's a blank page Quote Link to comment https://forums.phpfreaks.com/topic/66423-how-may-else-ifs-are-you-allowed-to-have/#findComment-332491 Share on other sites More sharing options...
trq Posted August 24, 2007 Share Posted August 24, 2007 Knowhere in that code do you output anything, what do you expect? Quote Link to comment https://forums.phpfreaks.com/topic/66423-how-may-else-ifs-are-you-allowed-to-have/#findComment-332497 Share on other sites More sharing options...
teng84 Posted August 24, 2007 Share Posted August 24, 2007 indent the code properly ??? ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/66423-how-may-else-ifs-are-you-allowed-to-have/#findComment-332499 Share on other sites More sharing options...
akitchin Posted August 24, 2007 Share Posted August 24, 2007 }else missing something? do somthing missing a pair of something? Quote Link to comment https://forums.phpfreaks.com/topic/66423-how-may-else-ifs-are-you-allowed-to-have/#findComment-332502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.