在if和else语句之间使用多个elseif语句编程 - php

时间:2017-04-09 07:38:22

标签: php html

对于学校作业我需要将html与php链接...对于作业,有多个问题,来自faq页面的单独答案。我使用多个else if语句解决了这个问题,但无论我的输入是什么问题,代码都会产生我为if语句回显的句子。

关于如何解决这个问题的任何想法?

我的PHP代码:

<?php

$question = $_POST['user_question'];

echo "The question you want the answer to is : $question ";

if ($question = "Is it possible for us to visit the roof of the new building? Even for a tour?") {

    echo "<br />";
    echo " Anything is possible at the American School of Warsaw. I would have to get a key and give the tour. 
    I think I would need a little advance notice to make sure I had time in my schedule. ";

} else if ($question = "Will the cafeteria ever have reasonable prices?") {

    echo "<br />";
    echo "The school is always interested in feedback from the students (and other community members) and would be willing to 
    listen to your concerns, including the cafeteria’s food quality and prices. A few months back I had a conversation with a student 
    council member about this very topic and I encouraged her to gather some data (she and others were planning to make a comparison 
    between our cafeteria’s prices and others in the city) and then I would facilitate a conversation with the school’s administration 
    and the cafeteria management. So far I haven’t heard anything back from her. However, I would encourage anyone with a concern to 
    make an appointment with me so we can discuss a plan of action and seek answers. ";
}

else if ($question = "Why did we get rid of the recycling stations in the cafeteria?") {

    echo "<br />";
    echo "Our last Director determined that the recycling stations were (a) not very attractive, and (b) not very effective. 
    To the latter point, it was determined that community members were not sorting the refuse and recycling effectively and 
    efficiently, and this was causing the cafeteria personnel to sort through the garbage to find the recyclables. 
    As well, plates and silverware were being discarded at an alarming and costly rate, costing the school a lot of money and 
    overall defeating the purpose of the stations. The “new system” -- that of placing trays in the racks -- allows the 
    cafeteria personnel to sort the recyclables themselves without digging through the garbage. May I ask why you’re not 
    appalled by the excessive use of plastic cups throughout the school?";
}

else if ($question = "Are you asking all these question because of a recent extraordinary event at our school?") {

    echo "<br />";
    echo "I think you’ll have to be more clear -- what’s the extraordinary event? The fire? The reason I am asking if you have any 
    questions is because Ms. Marci, one of our regular substitute teachers (and in case you didn’t know she’s also a former faculty 
    member), always asks the advisory students, whenever she subs, if they have any questions about the school. One day a couple of 
    weeks ago she passed on to me some of the questions, and I thought it would be a good idea to ask everyone.  ";
}


else if ($question = "How many assessments can students have in one day? Most students know the rule is to have a maximum of two, 
    but does it include both formative and summative? Some teachers have told them it is fine to have an assessment in every class as 
    long as it is not summative.") {

    echo "<br />";
    echo "As it is stated in the Student Handbook, students should not have more than two summative assessments in single school day. 
    These would include tests, orals, essays, labs, projects, etc. A summative assessment is that measure which is going to provide 
    further evidence of the student’s progress against the standards or criteria of the course and help the teacher determine the 
    achievement grade. Teachers are required to use the Google Assessment Calendar to share with their students when summatives are 
    taking place. The spirit of the policy is to ensure that students have the opportunity to properly prepare for the demonstration 
    of their learning. It is possible for a student to have a combination of summative and formative assessments scheduled in a day. 
    For example, a student might have math and social studies tests on the same day that an essay draft is due in English. 
    That student should be able to finish the essay draft (as long is it was not assigned the day before) at least one day before so 
    as not to impede studying for the math and social studies tests. Overall, it is the responsibility of teachers and students to 
    check the Google Assessment Calendar and make sure, within a reasonable amount of time, that students are not burdened with too 
    much work in too short of a timespan. If a student does find themselves in a situation where they have more than two summative 
    assessments scheduled for the same day, they should inform the teacher who told them last about the assessment (or put it last 
    on the assessment calendar) to work with them to reschedule. ";
}

else if ($question = "Where should students be checking for homework? If a teacher does not put homework up (online) in a timely 
manner, should students be penalized for not completing it? Can there be one place to check for it?") {

    echo "<br />";
    echo " Students have a right to know their homework prior to leaving the class. Teachers have their own way of posting homework 
    (Google Classroom, Google Sites, Google Docs, Moodle), however, the assignment must be clearly articulated to the students by the 
    end of class even if it might be posted online (as explained in class) at the end of the school day. It is the responsibility of 
    each individual student and teacher to ensure they understand where this homework is listed. If a student feels they are having 
    difficulty knowing when the homework is, they should approach the teacher and explain their challenge and ask for help on how to
     resolve the situation. ";
}

else if ($question = "There is a general feeling that the homework load in one section of a course taught by one teacher is 
    NOT equal to the homework load in another section of a course taught by another teacher. Is this fair?") {

    echo "<br />";
    echo " Teacher teams are strongly encouraged to give the students a similar experience, particularly when it comes to assessments.
     Just as there are differences between the personalities of teachers, there might be differences in teaching strategies, 
     learning activities, materials (such as texts), and even formative assessments used from section to section of the course. 
     However, all units of study should culminate in a similar summative assessment that all teachers will have collaboratively 
     created and then moderated on once it has been taken by the students. But back to the question -- should the homework load be 
     equal? No. And yes. It’s tough to say. Anyway, if this perceived imbalance is the source of some friction, perhaps the issue 
     should be discussed by all teachers who share a course, and I will encourage that discussion to happen. ";
}

else if ($question = "Would it be possible to reconsider advisory and lunch time and put it after 3rd period on Wednesdays? 
Clarification of question: Lunch poses a problem due to over crowdedness, unavailable seating, etc., not because students are hungry.") {

    echo "<br />";
    echo " We have heard the concerns regarding Wednesday. You might remember that back in October Mr. Sheehan ran a survey among the
     students to ask if they would like to move lunch to an earlier hour (after second period) on Wednesdays to avoid the problems, 
     and the great majority of students voted no to the move. So, and quite unfortunately, there is no way to move Advisory for this
      year. It is placed where it is to ensure that MS and HS lunches are staggered enough to get people through the lunch line. 
      We promise we will make it better for next year, however, please bear with us and stick to the plan for the remainder of the
       year. One more note: If the problem is in fact due to overcrowding and unavailable seating, then there is relief coming as 
       seniors finish classes on Friday, April 21. ";
}

else if ($question = "Is it possible to get earlier notification on what is happening on Day 9 I-block Flex? Clarification of question
: Sometimes emails don't come until the day of and also information is posted late to the TOK/CAS website.") {

    echo "<br />";
    echo " Usually, the Day 9 Flex block is in the weekly schedule posted in the Daily Bulletin before the beginning of the week.
     Mr. Beach, our IB DP Coordinator, is the one in charge of that I Block schedule, so if there are questions, please ask him what 
     is scheduled for the week. You can reach him at cbeach@aswarsaw.org, or simply contact him through the Google Classroom you 
     are enrolled in with him...or stop by and see him in the HS Office. He won’t bite. ";
}

else if ($question = "Do seniors have class after exams?") {

    echo "<br />";
    echo " No! The last day of classes for seniors is Friday, April 21. Mr. Sheehan is meeting with members of the senior class 
    very soon to plan out the seniors’ last week of classes and all of the events that take place. ";
}

elseif ($question = "When do we choose senior quotes? Senior superlatives?") {

    echo "<br />";
    echo " Those questions about senior quotes and superlatives are best directed to members of the Yearbook class or their teacher, 
    Mr. Miele. These are not planned by the administration and having nothing to do with the graduation ceremony. ";
}

else if ($question = "What emotional support is available for seniors and others?") {

    echo "<br />";
    echo " Mr. Munnerlyn and Ms. Raggio are always available for emotional support. As well, Mr. Sheehan and 
    Mrs. Berntson are available.  ";
}

else if ($question = "Can we do a therapy dog/puppy/cat day?") {

    echo "<br />";
    echo " Sure! That would be awesome. I saw that it was recently done at my last school and it seemed to be a very 
    effective stress reliever and a positive distraction from students’ busy, busy school lives. We just need someone to 
    step forward and take the lead on the initiative.  ";
}

else if ($question = "When is the senior walk?") {

    echo "<br />";
    echo " The Senior Walk takes place after the Senior Awards Assembly on the morning of Friday, May 26th, which is the day 
    before graduation. ";
}

else if ($question = "Do we have a prom? When is it?") {

    echo "<br />";
    echo " We do not have a prom. ASW has never taken on this tradition. The seniors have a 100-Day Celebration, or Studniowka,
     every year at the end of January here at school, and they, along with their parents, plan an “after-party” off campus. 
     The school does not sponsor that party. ";
}

else if ($question = " Where is Mr. Spooner? ") {

    echo "<br />";
    echo " A long-time sub in our community, Mr. Stan Spooner has not been able to sub for us due to his schedule and some recent 
    illnesses. It’s been a couple of years since he last subbed. ";
}

else if ($question = "Why do PE teachers make us go outside in freezing weather and rain, and then are surprised if we are sick and 
    miss three days of school?") {

    echo "<br />";
    echo " Have you asked your PE teacher this question? We suggest that you approach any teacher you have a question about why 
    something is happening and respectfully ask for clarification. You can also ask your parents to reach out to the teacher. 
    If you or your parent don’t feel comfortable approaching your teacher (any teacher) about something, then please enlist the 
    support of your counselor. Representing you and your concerns is something Mr. Munnerlyn and Ms. Raggio do regularly.
     In cases where the conflict persists or becomes greater, then an administrator will try to help. ";
}

else if ($question = "Why are most of the teacher substitutes incompetent to teach the subject they are substituting for?") {

    echo "<br />";
    echo " Unfortunately we do not have a cadre of “understudies”, highly trained educators from each subject area waiting in the 
    wings to step in when one of the teachers is sick or away from school. The people we employ as substitutes might have some 
    educational experience, but often they are stepping in briefly to simply manage the class and implement the lessons created and 
    left behind by your actual teacher. The subs do the best they can. Do you have an issue with a sub? Please speak to your teacher 
    when he or she returns to school, and the teacher can report the issue to an administrator. ";
}

else if ($question = "If we miss school days because teachers have meetings with other teachers, why do we have school 
longer on the end of the year although it's not our fault we skip school? ") {

    echo "<br />";
    echo " (I must admit, the question is a little confusing, in particular the part that says: “it’s not our fault we skip school”.) 
    Professional development days for teachers is a common practice in schools around the world, and they only amount to just a few 
    each year. They are put in place to allow the school to complete important work such as accreditation, strategic planning, or 
    curriculum development, tasks that need the immediate attention of every faculty and staff member in the school. However, the 
    reason school goes later into June is really due to a late August start date and the large number of holidays throughout the 
    school year. It has been discussed -- it comes up each year -- to decrease the number of school holidays, such as moving from 
    three weeks of vacation to two weeks around Christmas and New Year’s, so that we can finish earlier in June. Overall, we have a 
    diverse population in our community and everyone wants something different. In some ways the school calendar is a prime example 
    of compromise. Everyone gets something, but no one gets everything. Now, what is this about skipping school?  ";
}

else if ($question = "Is is possible that students receive a weekly email similar to what the teacher's receive and/or a 
    Google Classroom with the daily bulletin announcements because we check our email more frequently than PowerSchool?") {

    echo "<br />";
    echo " Answer is coming very soon! ";
}

else if ($question = "Can there be a limit to the number of summatives in a week? Because it seems that all classes end up having 
    summatives during the same week.") {

    echo "<br />";
    echo "Answer is coming very soon! ";
}

else if ($question = "Can students come to school to play sports or use facilities (the gyms and fitness room) during PD days? ") {

    echo "<br />";
    echo " Answer is coming very soon!";
}

else if ($question = "Is it possible for students to use the fitness room on Wednesdays right after school?") {

    echo "<br />";
    echo "Answer is coming very soon! ";
}

else if ($question = "What happens if there are more than 2 summative exams scheduled for one day? What can we do?") {

    echo "<br />";
    echo "Answer is coming very soon! ";
}

else if ($question = "What should we do if a teacher does not post homework in a timely manner? What can we actually do??") {

    echo "<br />";
    echo "Answer is coming very soon! ";
}

else {

    echo "<br />";
    echo "Sorry, I do not not have an answer for this question! Please don't hurt me ";

}

2 个答案:

答案 0 :(得分:0)

我心情很好,所以我打算给你答案。

您需要创建表单的PHP HTML

<!DOCTYPE HTML>  
<html>
//Do not forget to initialize the variables if you use text boxes to present your Answer
<form action="action_page.php"  method= "POST">
//Create as many questions as you like using imput box. 
<input type="text" name="question1" >
<input type="text" name="question2" >
...
<input type="submit" value="?"> 
// You can create input text boxes to present the result of your questions or just present with a simple echo
<input type="text" name="Answers_question1" value="<?php echo $Answer1; ?>">
<input type="text" name="Answers_question2" value="<?php echo $Answer2; ?>">
...
</form>
...
</html>

在你的action_page.php

    <?php
    if(isset($_POST['submit'])) {
       $quest1 = $_POST['question1'];
       switch ($quest1) {
              case "":
                  $Answer1 = "No question";
              case "Type principal colors?":
                  $Answer1 = "There is RED, BLUE, Yellow";
              case "What kind of colors can we get with Blue and Yellow?":
                  $Answer1 = "Green";
              default:
                   $Answer2 = "Your question was not found!!!";
       }
       $quest2 = $_POST['question2'];
       switch ($quest2) {
              case "":
                   $Answer2 = "No question";
              case "What kind of geometry?":
                   $Answer2 = "Square";
              case "What kind of solid?":  
                   $Answer2 = "Cube";  
              default:
                   $Answer2 = "Your question was not found!!!";
       }
    }

?>

将来,您必须更加具体地了解您的问题或输入您的代码或错误,以便社区可以为您提供帮助。

答案 1 :(得分:0)

实际上你有两个语法错误,

首先在php中我们使用“elseif”而不是“else if if”

你在if语句中错过了一个等号。所以,而不是

} else if ($question = "Will the c.......

你应该使用

} elseif ($question == "Will the c

但是,你的编码似乎并不是处理事物的优雅方法。至少你可以把你的Q&amp; A作为一个数组放到一个JSON文件中,这样你的代码看起来很整洁。