dsbfbz75185 2009-11-09 13:51
浏览 37
已采纳

决策树 - 必须是更好的方式......?

Below is my way, albeit a basic way of creating a Decision Tree...The problem is the CSS is getting way out of control and the code is just awful...is there a better way?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
#SwitchPicker .title{
width: 100%;
margin:auto;
text-align:center;
}
#SwitchPicker .twinanswer{
width:400px;
background:url(images/2ans.jpg) no-repeat;
margin:auto;
height:110px;
}
#SwitchPicker .answer-bottom-left {
padding-top:90px;
width:50%;
float:left;
}
#SwitchPicker .answer-bottom-right {
padding-top:90px;
width:50%;
float:left;
text-align:right;
}
#SwitchPicker .trioanswer{
width:400px;
background:url(images/3ans.jpg) no-repeat;
margin:auto;
height:110px;
}
#SwitchPicker .trio-answer-bottom-left {
padding-top:90px;
width:33%;
float:left;
}
#SwitchPicker .trio-answer-bottom-mid {
padding-top:90px;
width:33%;
float:left;
text-align:center;
}
#SwitchPicker .trio-answer-bottom-right {
padding-top:90px;
width:33%;
float:left;
text-align:right;
}
#SwitchPicker .answer{
width:50%;
float:left;
margin:auto;
text-align:center;
}
#SwitchPicker .answers{
width:40%;
padding-left:30%;
padding-right:30%;
margin:auto;
}
#SwitchPicker .detail {
display:none;
}
#SwitchPicker .answer-left {
margin-top:10px;
width:50%;
padding-left:13%;
}
#SwitchPicker .answer-right {
margin-top:10px;
width:50%;
padding-left:37%;
}
#SwitchPicker .answer-left-left {
margin-top:10px;
width:50%;
padding-left:3%;
}
#SwitchPicker .answer-left-right {
margin-top:10px;
width:50%;
padding-left:23%;
}
#SwitchPicker .answer-mid-left {
margin-top:10px;
width:50%;
padding-left:14%;
}
#SwitchPicker .answer-mid-right {
margin-top:10px;
width:50%;
padding-left:36%;
}
#SwitchPicker .answer-right-left {
margin-top:10px;
width:50%;
padding-left:27%;
}
#SwitchPicker .answer-right-right {
margin-top:10px;
width:50%;
padding-left:48%;
}
</style>
</head>
<?php
// Managed or Unmanaged
if ($_GET['st'] == "managed"){
$a1 = "answer-left";
$switch_type = $_GET['st'];
}
else if ($_GET['st'] == "unmanaged"){
$a1 = "answer-right";
$switch_type = $_GET['st'];
}
else if ($_GET['st'] == "smart"){
$a1 = "answer-mid";
$switch_type = $_GET['st'];
}
else {
echo "";
}
// Fast Ethernet or Gigabit
if (($_GET['st'] == "managed") && ($_GET['ss'] == 100)){
$a2 = "answer-left-left";
$switch_type = $_GET['st'];
$switch_speed = $_GET['ss'];
}
else if (($_GET['st'] == "managed") && ($_GET['ss'] == 1000)){
$a2 = "answer-left-right";
$switch_type = $_GET['st'];
$switch_speed = $_GET['ss'];
}
else if (($_GET['st'] == "unmanaged") && ($_GET['ss'] == 100)){
$a2 = "answer-right-left";
$switch_type = $_GET['st'];
$switch_speed = $_GET['ss'];
}
else if (($_GET['st'] == "unmanaged") && ($_GET['ss'] == 1000)){
$a2 = "answer-right-right";
$switch_type = $_GET['st'];
$switch_speed = $_GET['ss'];
}
else if (($_GET['st'] == "smart") && ($_GET['ss'] == 100)){
$a2 = "answer-mid-left";
$switch_type = $_GET['st'];
$switch_speed = $_GET['ss'];
}
else if (($_GET['st'] == "smart") && ($_GET['ss'] == 1000)){
$a2 = "answer-mid-right";
$switch_type = $_GET['st'];
$switch_speed = $_GET['ss'];
}
else {
echo "";
}
?>
<body id="SwitchPicker">
<div class="title">Small Business Decision Tree</div>
<div class="title">Managed or Unmanaged</div>
<div class="trioanswer">
  <div class="trio-answer-bottom-left"><a href="index.php?st=managed">Managed</a></div>
  <div class="trio-answer-bottom-mid"><a href="index.php?st=smart">Smart</a></div>
  <div class="trio-answer-bottom-right"><a href="index.php?st=unmanaged">Unmanaged</a></div>
</div>
<? 
if (isset($_GET['st'])) {
echo"
  <div class=\"" .$a1. "\">
    <div class=\"title\">Switch Speed?</div>
        <div class=\"twinanswer\">
            <div class=\"answer-bottom-left\"><a href=\"index.php?st=" .$switch_type. "&ss=100\">Fast Ethernet (10/100)</a></div>
            <div class=\"answer-bottom-right\"><a href=\"index.php?st=" .$switch_type. "&ss=1000\">GigabitEthernet (1000)</a></div>
        </div>
    </div>";
    }
else {
echo "";
}
?>
<?
if (isset($_GET['ss'])) {
echo"
    <div class=\"" .$a2. "\">
    <div class=\"title\">Switch Size?</div>
        <div class=\"twinanswer\">
            <div class=\"answer-bottom-left\"><a href=\"index.php?st=" .$switch_type. "&ss=" .$switch_speed. "&ssize=desk\">Desktop</a></div>
            <div class=\"answer-bottom-right\"><a href=\"index.php?st=" .$switch_type. "&ss=" .$switch_speed. "&ssize=rack\">Rack-mountable</a>         </div>
        </div>
    </div>";
    }
else {
echo "";
}
?>
</body>
</html>

Thanks, B.

  • 写回答

2条回答 默认 最新

  • duanliu6083 2009-11-09 14:05
    关注

    At first you could take the lines

    $switch_type = $_GET['st'];
    $switch_speed = $_GET['ss'];
    

    out of the conditions, they are the same everywhere. Just do it once before or after the if/elses.

    Furthermore I see, that each sub-part of $a2 depends on a specific condition. Maybe you can construct it the following (pseudo-code) way:

    ...
    //$a2 always starts the same
    $a2 = "answer";
    
    // Type of line
    switch($_GET['st']) {
      case "managed":
        $a2 = $a2 + "-left"; break;
      case "unmanaged":
        $a2 = $a2 + "-right"; break;
      case "smart":
        $a2 = $a2 + "-mid"; break;
    }
    
    // speed of line
    switch($_GET['ss']) {
      case 100:
        $a2 = $a2 + "-left"; break;
      case 1000:
        $a2 = $a2 + "-right"; break;
    }
    ....
    

    After that $a2 should hold your combined values like 'answer-left-right' and so on. A similar approach could be done with $a1 but I chose $a2 for the example as it's better suited here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因