【问题标题】:Show DB data in framework7 app在 framework7 应用程序中显示数据库数据
【发布时间】:2016-12-18 12:33:45
【问题描述】:

我想显示来自 MySQL DB 的数据。表“mytable1”有 4 列:fname、lname、school 和 city。该表中有 10 行数据。所以我的代码是:

DB CONNECTION

$sql = "SELECT * FROM mytable1";

$result = $conn->query($sql);

$mycontent = array();

while($row = $result->fetch_assoc()){
 array_push($mycontent, $row);
}

$newcontent = json_encode($mycontent);

echo $newcontent ;

在 myapp.js 我有:

$$.ajax({
        url:"ajaxdbtest.php",
        type:"get",
        dataType:"json",
        success: function(data)
        {
            $$( ".showcontenthere" )
            .append( "<br />data.fname )
            .append( "<br />data.lname )
            .append( "<br />data.school )
            .append( "<br />data.city );

        }
    });

我无法显示任何数据。我希望能够显示包含 10 行数据的表中的所有数据。我究竟做错了什么?

谢谢。

【问题讨论】:

    标签: php mysql html-framework-7


    【解决方案1】:

    如果您使用上面相同的代码来发送 ajax 调用,那么您需要这样修复它:

    $$.ajax({
            url:"ajaxdbtest.php",
            type:"get",
            dataType:"json",
            success: function(data)
            {
                $$( ".showcontenthere" )
                .append( "<br />" + data.fname )
                .append( "<br />" + data.lname )
                .append( "<br />" + data.school )
                .append( "<br />" + data.city );
    
            }
        });
    

    【讨论】:

    • 你做了什么不同的事情?代码和我的一样。
    • 在 append 函数中,您以错误的方式将字符串与 json 变量混合,不是吗?
    • 哦对不起..这是一个错字。我的原始代码没有。谢谢你。
    • 那很好,你能分享一个你的项目的现场样本来帮助你找到问题吗?
    • 它在 localhost 上工作,但不在 Phonegap 应用程序上。我想我现在需要对 phonegap 进行一些调整。
    猜你喜欢
    • 2019-10-31
    • 2015-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多