dpbdl44228 2013-12-03 16:12
浏览 40
已采纳

w3验证器给出了导航错误

I've been doing some researching and discovered this nice website http://validator.w3.org/

After running a test i see that my navigation get loads of error.

The error i get is the ul in the coding. I don't close it off because i give it it styling if a condition is met else close it.
But this is not a valid solution according to w3 which gives me some errors.

Can you help me find a fix for my navigation so it gets valid?

With thanks Jim

<ul id="nav-container">
    <?php

    $select_category = mysql_query("SELECT * FROM menu WHERE hidden = 0 ORDER BY menu ASC");
    while ($ln = mysql_fetch_array($select_category)) {
        $idcat = $ln['nmr'];
        $catname = $ln['menu'];
        $catsname = str_replace(' ', '-', $ln['menu']);

        echo '<li>';
        if($catname == "carparts") {
            echo '<a href="http://www.mywebsite.com/carparts.php" title="'.$catname.'"><span><strong>'.$catname.'</strong></span></a>';
        } else {
            echo '<a href="http://www.mywebsite.com/'.$idcat.'/'.$catsname.'/" title="'.$catname.'"><span><strong>'.$catname.'</strong></span></a>';
        }

This gives me the errors: (fixed)

echo '<ul';

if(isset($_GET['cats'])) {
    if ($_GET['cats'] == $idcat) {
        echo ' style="display:block;">';
    } else {
        echo '>';
    }

The fix: also deleted the closing bracket at the end.

echo '<ul';

if(isset($_GET['cats']) && $_GET['cats'] == $idcat){
    echo ' style="display:block;">';
} else {
    echo '>';
}

/fix finish

//Error finish

$select_sub = mysql_query("SELECT * FROM submenu WHERE nmrmenu = '$idcat' AND hidden = 0");
while ($lsub = mysql_fetch_array($select_sub)) {
    $subname = $lsub['submenu'];
    $subsname = str_replace(' ', '-', $lsub['submenu']);
    $pil = '&raquo;';
    $brnr = $lsub['nmr'];

    if(isset($_GET['cat'])) {
        if ($_GET['cat'] == $brnr) {
            $subname = '<u>'.$lsub['submenu'].'</u>';
        } else {
            $subname = $lsub['submenu'];
        }
    }

    echo '<li><a href="http://www.mywebsite.com/'.$lsub['nmr'].'/'.$subsname.'/"><span><strong> '.$subname.' </strong></span></a></li>';
}

echo '</ul>';
echo '</li>'; // to this location
}
  echo '</li>'; //relocated this up one line
} **//Deleted this one!** 

?>
</ul>

Update
The output gets like this which is horrible: (fixed)

<ul</li><li><a href="http://www.mywebsite.com/x/name/" title="name"><span><strong>name</strong></span></a>

<ul</li><li><a href="http://www.mywebsite.com/x/name/" title="name"><span><strong>name</strong></span></a><ul</li>

New: now the ul problem is gone, but it's complaining about the li's. Any clue why?

Error: document type does not allow element "li" here; missing one of "ul", "ol", "menu", "dir" start-tag

<ul id="nav-container">
    <li>
        <a href="http://www.mywebsite.com/x/name/" title="name"><span><strong>name</strong></span></a>

        <ul>
            <li>
                <a href="http://www.mywebsite.com/x/name/"><span><strong> name </strong></span></a>
            </li>
        </ul>
    </li>
</ul>

/update

  • 写回答

1条回答 默认 最新

  • dsizd368332 2013-12-04 09:24
    关注

    You have </ul> and then immediately follow it with a <li>. You can't have a list item outside of a list.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: