[英]How can I create a desicion tree in php using these data felds?
So the assignment wants us to make a decision tree based on 3 to 4 variables.所以作业要我们根据 3 到 4 个变量制作决策树。 there is supposed to be a result for each of these values.
这些值中的每一个都应该有一个结果。
The first file is an HTML document has a form with drop down menus.第一个文件是一个带有下拉菜单的表单的 HTML 文档。 For each combination of 3 variables color, size, and shape.
对于 3 个变量颜色、大小和形状的每种组合。 There needs to be a echo out of something like a fruit.
需要从水果之类的东西中发出回声。 So if user selects (shape circle) (color red) and (size medium) that the output becomes apple for example.
因此,如果用户选择(形状圆圈)(红色)和(大小中等),则输出例如为苹果。
so I am thinking multiple if statements inside each other but how?所以我在考虑多个 if 语句,但是如何? I tried and so far no luck.
我试过了,到目前为止没有运气。 So how should the PHP be done?
那么PHP应该怎么做呢?
HTML CODE
----------
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<!--this is a simple fieldset with the dropboxes put in them-->
<fieldset>
<legend>Select your fruit!</legend>
<form class="" action="tree.php" method="post">
<select name="Color">
<option value="Blank"></option>
<option value="Red">Red</option>
<option value="Purple">Purple</option>
<option value="Yellow">Yellow</option>
</select>
<select name="Size">
<option value="Blank"></option>
<option value="Small">Small</option>
<option value="Medium">Medium</option>
<option value="Large">Large</option>
</select>
<select name="Shape">
<option value="Blank"></option>
<option value="Round">Round</option>
<option value="Square">Square</option>
<option value="Elipse">Elipse</option>
</select>
<input type="submit" />
</form>
</fieldset>
</body>
</html>
first create a master table with possible result set where the table may have fields like "Shape | Color | Size | Fruit Name" .首先创建一个带有可能结果集的主表,其中该表可能具有“形状 | 颜色 | 大小 | 水果名称”等字段。 Now catch each of the drop-down value on submit and catch them in the tree.php page .
现在在提交时捕获每个下拉值并在 tree.php 页面中捕获它们。 Now search the master table for result with the values obtained and echo the result you will get from the database .
现在用获得的值搜索主表的结果,并回显您将从数据库中获得的结果。
If you do not want to use a database then you have to use multiple if-else statements or switch case which will definitely shorten your codes .如果您不想使用数据库,那么您必须使用多个 if-else 语句或 switch case,这肯定会缩短您的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.