php侧边栏和页脚里面的主页

时间:2015-02-26 20:11:58

标签: php css

我帮助开发我学校的网站,我无法弄清楚为什么在某个页面上,侧边栏和页脚会进入主页。即使我认为说管理员的代码是相同的代码并且对我来说看起来是一样的,它只能用于监管和厨房这两件事。

这是用于生成教师页面的代码

以下链接会将您带到已损坏的页面,因为我无法发布图片 http://gwhs.kana.k12.wv.us/academics/display.php?action=teacher&id=103

虽然下面的链接会将您带到实际可行的链接 http://gwhs.kana.k12.wv.us/academics/display.php?action=teacher&id=24

如果你想要这个代码的整个文件让我知道,我会发布一个链接

function dTeacher() {
        global $db, $id;
        if ($stmt = $db->prepare("SELECT name, department, schedule, education, whyteach, phone, email, image, quote FROM teachers WHERE id = ?"))
        {
            $stmt->bind_param('i', $id);
            $stmt->execute();
            $res = $stmt->get_result();
            $row = $res->fetch_assoc();
            $stmt->close();
            $schedule = array();
            $schedule = explode(",",$row['schedule']);
            $education = explode(",",$row['education']);
            $noshow = array(20, 14, 25, 15, 24, 21, 23);
            print '<h1>Viewing '.$row['name'].'\'s Profile!</h1>';
            if ($row['image']) {
                print '<img style="max-width:40%; display: block; margin: 2% auto;" src="'.$row['image'].'" alt="Teacher Image Here">';
            }
            if (!(in_array($row['department'], $noshow))) {
            print '<h3>Schedule</h3>
            <table id="maindata">
                <tr id="head"><td style="width:30%;">Period</td><td style="width:70%;">Class</td></tr>';
                for ($i=0; $i<count($schedule); $i++)
                {
                $oddeven = ($i%2==0) ? "even" : "odd";
                $scnum = $schedule[$i];
                $scresult = $db->query("SELECT id, name FROM classes where id = {$scnum} LIMIT 1");
                $scrow = $scresult->fetch_assoc();
                if ($scnum == 1337) {
                $scrow['name'] = "OFF";
                } //off periods
                print '<tr id="'.$oddeven.'"><td style="width:30%;">'.$i.'</td><td style="width:70%;"><a href="/academics/display.php?action=dclass&id='.$scrow['id'].'">'.$scrow['name'].'</a></td></tr>';
                }
            }
            if ($row['education']) {
                print "</table><h3>Education</h3>";
                for ($i=0; $i<count($education); $i++)
                {
                $oddeven = ($i%2==0) ? "even" : "odd";
                print '<table id="maindata"><tr id="'.$oddeven.'"><td>'.$education[$i].'</td></tr>';
                }
                print '</table>';
                }
            if ($row['phone'] || $row['email']) {
                print '
                <h3>Contact</h3>
                <table id="maindata"><tr id="even"><td style="width:30%;">Phone</td><td>'.$row['phone'].'</td></tr>
                <tr id="odd"><td style="width:30%;">Email</td><td>'.$row['email'].'</td></tr></table>';
            }
                if ($row['whyteach'] != "") {
                print '<h3>Why do you teach?</h3>
                <table id="maindata"><tr id="even"><td><p>'.$row['whyteach'].'</p></td></tr></table>';
                }
                if ($row['quote'] != "") {
                print '<h3>Favorite Quote</h3>
                <table id="maindata"><tr id="even"><td><p>'.$row['quote'].'</p></td></tr></table>';
                }
        }
        else {
        print "Error with your request.";
        die();
        }
    }

2 个答案:

答案 0 :(得分:0)

第一句话:你应该重新考虑布局。创建多个表来显示页面内容不是最好的方法,而且ID必须是唯一的。因此,对于有效的HTML,您不能拥有ID为maindata的多个表。

正如评论中cmorrissey所述,除非您输入下一个if语句,否则您不会关闭第一个表。此外,这部分

if ($row['education']) {
  print "</table><h3>Education</h3>";
  for ($i=0; $i<count($education); $i++) {
    $oddeven = ($i%2==0) ? "even" : "odd";
    print '<table id="maindata"><tr id="'.$oddeven.'"><td>'.$education[$i].'</td></tr>';
  }
  print '</table>';
}
您的代码的

关闭了之前的<table id="maindata">,但在循环的每次迭代中都会打开一个新代码。循环之后,你只关闭其中一个。所以如果它是正确的,你想要创建这些表的多个,你也应该在循环中关闭它们:

for ($i=0; $i<count($education); $i++) {
  $oddeven = ($i%2==0) ? "even" : "odd";
  print '<table id="maindata"><tr id="'.$oddeven.'"><td>'.$education[$i].'</td></tr>';
  print '</table>';
}

答案 1 :(得分:0)

你有一个错误,你没有关闭表标签:

        if (!(in_array($row['department'], $noshow))) {
        print '<h3>Schedule</h3>
        <table id="maindata">
            <tr id="head"><td style="width:30%;">Period</td><td style="width:70%;">Class</td></tr>';
            for ($i=0; $i<count($schedule); $i++)
            {
                $oddeven = ($i%2==0) ? "even" : "odd";
                $scnum = $schedule[$i];
                $scresult = $db->query("SELECT id, name FROM classes where id = {$scnum} LIMIT 1");
                $scrow = $scresult->fetch_assoc();
                if ($scnum == 1337) {
                    $scrow['name'] = "OFF";
                } //off periods
                print '<tr id="'.$oddeven.'"><td style="width:30%;">'.$i.'</td><td style="width:70%;"><a href="/academics/display.php?action=dclass&id='.$scrow['id'].'">'.$scrow['name'].'</a></td></tr>';
            }
            echo "</table>";
        }

因此,当配置文件具有“计划”时,表格未关闭,页面将显示错误。

在此关闭它:

if ($row['education']) {
  print "<h3>Education</h3>";

通过两次修改,网络应该可以正常工作。

看看这个HTML验证器,它会帮助你:

http://validator.w3.org/check?uri=http%3A%2F%2Fgwhs.kana.k12.wv.us%2Facademics%2Fdisplay.php%3Faction%3Dteacher%26id%3D103&charset=%28detect+automatically%29&doctype=Inline&group=0

最好的问候。