Php 如何从mysql向listview jquery mobile显示数据?

Php 如何从mysql向listview jquery mobile显示数据?,php,javascript,jquery,mysql,mobile,Php,Javascript,Jquery,Mysql,Mobile,我是android编程的初学者。我有一些问题让我感到困惑 我的问题是我想在listview上显示mysql数据库表中的数据列表。 我一直在努力学习本教程,并对其进行了修改,使之适合我的程序。但是我的代码没有显示数据库中的数据 请帮帮我。谢谢 这是我的一些代码 这是我的html代码 <ol id="top10list" data-role="listview" data-theme="a"> </ol> 这是我的php代码 <?php include 'conf

我是android编程的初学者。我有一些问题让我感到困惑

我的问题是我想在listview上显示mysql数据库表中的数据列表。 我一直在努力学习本教程,并对其进行了修改,使之适合我的程序。但是我的代码没有显示数据库中的数据

请帮帮我。谢谢

这是我的一些代码 这是我的html代码

<ol id="top10list" data-role="listview" data-theme="a"> </ol>

这是我的php代码

<?php
include 'config.php';

$sql = "select m.namamovie, m.description from top10 t left outer join movie m on t.idmovie = m.idmovie";

try {
    $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $dbh->prepare($sql);
    $stmt->bindParam("idtop10", $_GET[idtop10]);
    $stmt->execute();
    $top10 = $stmt->fetchObject();
    $dbh = null;
    echo '{"item":'. json_encode($top10) .'}';
} catch(PDOException $e) {
    echo '{"error":{"text":'. $e->getMessage() .'}}';
}
?>

这是我的javascript代码

var serviceUrl ="..\MovieManiac1.0\assets\www\";
var top10s;

$('#top10list').bind('pageinit', function(event) {
    getTop10List();
});

function getTop10List() {
    $.getJSON(serviceURL + 'gettop10.php', function(data) {
    $('#top10list li').remove();
    top10s = data.items;
    $.each(top10s, function(index, top10) {
        $('#top10list').append('<li><a href="top10.php?id=' + top10.idmovie + '">' + '<h4>' + movie.moviename + '</h4>' + '<p>' + movie.moviename + '</p>' + '<p>' + movie.description + '</p>'+ '</a></li>'); 
    $('#top10list').listview('refresh');
    });
    }
}
var serviceUrl=“..\MovieManiac1.0\assets\www\”;
var-top10s;
$('#top10list').bind('pageinit',函数(事件){
getTop10List();
});
函数getTop10List(){
$.getJSON(serviceURL+'gettop10.php',函数(数据){
$(“#top10list li”).remove();
top10s=数据项;
$。每个(top10s,函数(索引,top10){
$(“#top10list”)。追加(“
  • ”); $(“#top10list”).listview('refresh'); }); } }
    那么php是否显示了任何错误,或者您无法在android中显示数据?我看到这行var serviceUrl=“..\MovieManiac1.0\assets\www\”;您正在尝试从android手机上的php文件中获取db结果?我不认为soi使用eclipse构建了我的android项目。因此,我将我的php、javascript和html文件放在了www文件夹中。我没有从php中得到错误显示,数据也无法显示。我在android虚拟设备和浏览器上进行了测试,也没有出现。如果您的php文件oesent输出结果:您做错了。打开错误报告并首先调试php文件。此外,我认为您将无法从android设备连接到远程数据库,请尝试,如果是这样,您需要调用远程php脚本,该脚本将返回json响应,然后在应用程序中使用它