Show DB data in framework7 app

2.3k views Asked by At

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

There are 1 answers

5
tinyCoder On

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

        }
    });