【问题标题】:jQuery Mobile Collapsibles with DatabasesjQuery Mobile 可折叠数据库
【发布时间】:2014-06-05 10:39:48
【问题描述】:

我正在尝试使用 jQuery Mobile Collapsibles 创建一个包含可折叠内容的网页。我指的是this。我想显示 $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 } ?>

【问题讨论】:

    标签: javascript php jquery jquery-mobile


    【解决方案1】:

    您的 HTML 中有错误。

    基本上你是在 HTML 标签关闭后导出数据库数据:

    <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
    

    改成这样:

    <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 文件,它将失败
    • 知道了..问题出在扩展上。非常感谢您指出。
    猜你喜欢
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 2012-01-21
    • 1970-01-01
    • 2011-10-03
    相关资源
    最近更新 更多