Javascript jQuery Mobile可折叠数据库

Javascript jQuery Mobile可折叠数据库,javascript,php,jquery,jquery-mobile,Javascript,Php,Jquery,Jquery Mobile,我正在尝试使用jquerymobilecomplables创建一个包含可折叠内容的网页。我指的是。我想将$row['Host']显示为标题,将$row['IP']显示为内容。我的脚本没有显示任何内容?我错在哪里 <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://code

我正在尝试使用jquerymobilecomplables创建一个包含可折叠内容的网页。我指的是。我想将$row['Host']显示为标题,将$row['IP']显示为内容。我的脚本没有显示任何内容?我错在哪里

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>
</body>
</html>


<?php
$con = mysql_connect("127.0.0.1", "root", "pass");
if (!$con) {
    die("Error: " . mysql_error());
}


mysql_select_db("mydb", $con);
$result = mysql_query("SELECT * FROM mytbl");
?>

<?php 
// display the results returned
while ($row = mysql_fetch_array($result)) {
?>
<div data-role="collapsible" data-collapsed="true">
   <h3><?=$row['Host']?></h3>
   <p><?=$row['IP']?><p>
</div>
<?php } ?>



您的HTML中有一个错误

基本上,您是在HTML标记关闭后导出DB数据:

<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
        <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
    </head>
    <body>
    </body>
</html>

YOUR PHP CODE IS HERE

您的PHP代码在这里
将其更改为:

<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
        <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
    </head>
    <body>

        <?php
        $con = mysql_connect("127.0.0.1", "root", "pass");
        if (!$con) {
            die("Error: " . mysql_error());
        }


        mysql_select_db("mydb", $con);
        $result = mysql_query("SELECT * FROM mytbl");
        ?>

        <?php 
        // display the results returned
        while ($row = mysql_fetch_array($result)) {
        ?>
        <div data-role="collapsible" data-collapsed="true">
           <h3><?=$row['Host']?></h3>
           <p><?=$row['IP']?><p>
        </div>
        <?php } ?>

    </body>
</html>



谢谢,我不是网络程序员。很抱歉,我犯了这个错误,但我还是没有得到结果?它只是空的?你看到我的脚本有什么错误吗?你的文件有php扩展名吗?如果文件名具有php扩展名,则代码运行正常;如果文件具有html扩展名,且php web服务器未配置为加载html文件,则代码将失败。问题在于扩展名。非常感谢你指出这一点。