显示数据库中的<ul> </ul>

时间:2015-01-06 19:35:08

标签: php mysql

我正在创建一个脚本,我使用我的数据库来显示页面的菜单。但我遇到了一个问题......

我网站上的脚本。 :Click here

问题

所以我有这段代码

更新后的代码和添加的链接

                                <!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Heroic Features - Start Bootstrap Template</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/heroic-features.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

    <!-- Navigation -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">Start Bootstrap</a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
<?php
$db = new mysqli('xxxxxxxxxxx');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

if($_GET['action'] == '')
            {
            $sql = "SELECT * FROM li_psp";

if(!$result = $db->query($sql)){
    die('There was an error running the query [' . $db->error . ']');
}
while($row = $result->fetch_assoc()){
echo "                    <li>
                        <a href='{$row['li_href']}'>{$row['li_label']}</a>
                        </li>";



}

}   

                        ?>

<?php
$db = new mysqli('xxxxxxxxxxx');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

if($_GET['action'] == '')
            {
            $sql = "SELECT * FROM ul_psp";
error_reporting(E_ALL);
if(!$result = $db->query($sql)){
    die('There was an error running the query [' . $db->error . ']');
}
while($row = $result->fetch_assoc()){
echo "<li class='dropdown'>
              <a href='#' class='dropdown-toggle' data-toggle='dropdown'>{$row['ul_name']} <b class='caret'></b></a>
              <ul class='dropdown-menu'>";

if($_GET['action'] == '')
            {
            $sql = "SELECT * FROM ul_data_psp WHERE belong_to = {$row['ul_name']}";

if(!$result = $db->query($sql)){
    die('There was an error running the query [' . $db->error . ']');
}
while($row = $result->fetch_assoc()){
echo "                    <li>
                        <a href='{$row['ul_data_href']}'>{$row['ul_data_label']}</a>
                        </li>";




echo "</ul>
            </li>";



}

}   
}
}
                        ?>

                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>

但由于某种原因,它不起作用。我收到此错误:Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/u799303375/public_html/beta/include/menu.php on line 98

我尝试了什么?

我尝试更改所有“to”但它没有用,我需要帮助修复此代码,如果你有任何其他的东西我可以做得更好请告诉它!谢谢!

1 个答案:

答案 0 :(得分:-1)

您的引号格式不正确。将变量不直接放入字符串中,用.

连接它们
echo '<li><a href=' . $row['ul_data_href'] . '>' . $row['ul_data_label'] . '</a></li>'