主版中的 PHP 侧边栏和页脚


php sidebar and footer inside main

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

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

下面的链接将带您到损坏的页面,因为我无法发布图片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();
        }
    }

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

        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

此致敬意。

第一句话:你应该重新考虑布局。创建多个表来显示页面内容不是最佳方法,此外 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>';
}