MDanz Posted September 22, 2009 Share Posted September 22, 2009 i got like 874 lines of code.. is there a way i can simplify these, since there are 4 duplicates with different changes inside if and else statements.. e.g. if{ if{ code 1 } else { code 2 } } else{ if{ code 3 } else { code 4 } } do i use class or include?.. it will be way easier since i'm lost in brackets.. Link to comment https://forums.phpfreaks.com/topic/175114-solved-help-with-simplifying/ Share on other sites More sharing options...
Bricktop Posted September 22, 2009 Share Posted September 22, 2009 Hi MDanz, It's hard to say without seeing more of your code, there are numerous ways of streamlining code, some better than others depending on the source code in question. If you post more code we'll be able to give a more definitive answer. Link to comment https://forums.phpfreaks.com/topic/175114-solved-help-with-simplifying/#findComment-922931 Share on other sites More sharing options...
MDanz Posted September 22, 2009 Author Share Posted September 22, 2009 this is what i attempted but not working <?php $radiobutton = $_GET['radiobutton']; if($radiobutton == 'on') { include("searchtopic.php"); } else { include("searchnormal.php"); } ?> i want if radiobutton is checked on the submit form then use searchtopic code otherwise use searchnormal code.. this was just an attempt i saved the code in different files.. if another way is easier i'm welcome to do that.. Link to comment https://forums.phpfreaks.com/topic/175114-solved-help-with-simplifying/#findComment-922935 Share on other sites More sharing options...
RichardRotterdam Posted September 22, 2009 Share Posted September 22, 2009 What does your form look like? Link to comment https://forums.phpfreaks.com/topic/175114-solved-help-with-simplifying/#findComment-922937 Share on other sites More sharing options...
MDanz Posted September 22, 2009 Author Share Posted September 22, 2009 What does your form look like? <form action="test.php" method="get"> <center> <input name="search" type="text" value='' size="25" /> <input type="submit" name="submit" value="search"> <input name="radiobutton" type="radio" value="radiobutton"> </center> </form> Link to comment https://forums.phpfreaks.com/topic/175114-solved-help-with-simplifying/#findComment-922938 Share on other sites More sharing options...
RichardRotterdam Posted September 22, 2009 Share Posted September 22, 2009 For your php code to work your radio button should have a value "on" <input name="radiobutton" type="radio" value="on"> <input name="radiobutton" type="radio" value="off"> Link to comment https://forums.phpfreaks.com/topic/175114-solved-help-with-simplifying/#findComment-922939 Share on other sites More sharing options...
MDanz Posted September 22, 2009 Author Share Posted September 22, 2009 thx alot got it working... is there a way to do it without radiobutton like checkbox.. because i prefer just one item showing not two. e.g. <input name="checkbox" type="checkbox" value="checkbox"> if($checkbox == 'checked') Link to comment https://forums.phpfreaks.com/topic/175114-solved-help-with-simplifying/#findComment-922943 Share on other sites More sharing options...
RichardRotterdam Posted September 22, 2009 Share Posted September 22, 2009 That's just a matter of changing type="radio" to type="checkbox" and removing the off radio button. edit Again your value should match the if condition you have your value set to "checkbox" not "on" Link to comment https://forums.phpfreaks.com/topic/175114-solved-help-with-simplifying/#findComment-922946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.