verdrm Posted September 30, 2007 Share Posted September 30, 2007 Can anyone tell me the context in which to use PHP like this: $show_calendar = false; I would like to hide a function if it is set to "false" or show it if it is set to "true". Quote Link to comment https://forums.phpfreaks.com/topic/71295-solved-showhide-truefalse/ Share on other sites More sharing options...
Wuhtzu Posted September 30, 2007 Share Posted September 30, 2007 <?php //This could be set by the user through a form or something $show_calendar = false; //Determine whether or not to show the calendar if($show_calendar) { //Code to show the calendar } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71295-solved-showhide-truefalse/#findComment-358650 Share on other sites More sharing options...
shocker-z Posted September 30, 2007 Share Posted September 30, 2007 you could use it like this function calendarfunction($true_or_false) { if ($true_or_false == true) { echo 'Calandar is active'; } else { echo 'Calandar is inactive'; } } $show_calendar = false; calendarfunction($show_calendar); If that is what you ment? Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/71295-solved-showhide-truefalse/#findComment-358653 Share on other sites More sharing options...
teng84 Posted September 30, 2007 Share Posted September 30, 2007 simple and short $calendar = ($condition == true)? showfuctioncalendar($etc):''; i guess hide function is no good but i guess what you mean is call function when needed Quote Link to comment https://forums.phpfreaks.com/topic/71295-solved-showhide-truefalse/#findComment-358668 Share on other sites More sharing options...
verdrm Posted September 30, 2007 Author Share Posted September 30, 2007 Thanks. I worked it out. Now my question is this. I have a form that can update the database with the user's choice (either 'true' or 'false'). Example: $showcalendar = true; Is there a way to replace "true" above with a statement that can interact with MySQL and find out whether they chose TRUE or FALSE? So if the user chose "false" it wouldn't show up? Quote Link to comment https://forums.phpfreaks.com/topic/71295-solved-showhide-truefalse/#findComment-358711 Share on other sites More sharing options...
teng84 Posted September 30, 2007 Share Posted September 30, 2007 simply over write it select * from table where etc.... then considering you have a result if ($result[selection]== false){ $showcalendar = false; } $calendar = ($condition == true)? showfuctioncalendar($etc):''; Quote Link to comment https://forums.phpfreaks.com/topic/71295-solved-showhide-truefalse/#findComment-358714 Share on other sites More sharing options...
verdrm Posted September 30, 2007 Author Share Posted September 30, 2007 I would like to do it this way, if possible: $show = mysql_query("SELECT choice FROM calendar WHERE dom_id = '$domain_id' "); $showcalendar = $show; <-- THIS VALUE, if true, would show calendar...$show needs to be able to be replaced with TRUE or FALSE //Determine whether or not to show the calendar if($showcalendar == true) { The problem that I am having is how do I query MySQL to deliver that value and replace "$show" with that value? Quote Link to comment https://forums.phpfreaks.com/topic/71295-solved-showhide-truefalse/#findComment-358715 Share on other sites More sharing options...
teng84 Posted September 30, 2007 Share Posted September 30, 2007 maybe $show = $_POST['value'];//i dont know if you have post but this might be good sample $query = "SELECT choice FROM calendar WHERE dom_id = '$domain_id' "; $result=mysql_query($query); if ($result){ $value = mysql_fetch_array($result); if ($show == $value['choice']){ //just show calendar base on the query } else{ mysql_query('update calendar set choice = "$show" where yourcondition'); //show calendar based on the users post } } Quote Link to comment https://forums.phpfreaks.com/topic/71295-solved-showhide-truefalse/#findComment-358718 Share on other sites More sharing options...
verdrm Posted October 1, 2007 Author Share Posted October 1, 2007 I think what I'm looking for is a bit less complicated. Basically I just want to query the column "choice", and if that column has the value "false" it should not show the calendar. If the value is "true", then it should. The problem I am having is in BOLD. I can SELECT the choice from the database, but how do I replace $value with that choice? $value = MySQL SELECT statement here.... $showcalendar = $value; //Determine whether or not to show the calendar if($showcalendar == true) { Quote Link to comment https://forums.phpfreaks.com/topic/71295-solved-showhide-truefalse/#findComment-358724 Share on other sites More sharing options...
verdrm Posted October 1, 2007 Author Share Posted October 1, 2007 Nevermind. I figured it out. Quote Link to comment https://forums.phpfreaks.com/topic/71295-solved-showhide-truefalse/#findComment-358727 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.