doumen6605 2016-12-18 12:33
浏览 15

在framework7 app中显示DB数据

I want to show the data from MySQL DB. The table 'mytable1' has 4 columns: fname, lname, school and city. There are 10 rows of data in that table. So my code is:

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 ;

In myapp.js I have:

$$.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 );

        }
    });

Im not able to show any data. I want to be able to show all the data from the table which has 10 rows of data. What am i doing wrong?

Thanks.

  • 写回答

1条回答 默认 最新

  • dongzhuo1930 2016-12-18 20:35
    关注

    If you are using the same code above for sending the ajax call, then you need to fix it like that:

    $$.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 );
    
            }
        });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗