-3

所以我几天前从“ http://coenraets.org/blog/2011/10/sample-application-with-jquery-mobile-and-phonegap/ ”获得了这个phonegap应用程序的样本,其中包含file.html

<!DOCTYPE HTML>
<html>
<head>
<title>Employee Directory</title>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<link rel="stylesheet" href="css/jquery.mobile-1.0rc1.min.css" />
<link rel="stylesheet" href="css/styles.css" />
</head>

<body>

<div id="employeeListPage" data-role="page" >

<div data-role="header" data-position="fixed">
    <h1>Employee Directory</h1>
</div>

<div data-role="content">
     <ul id="employeeList" data-role="listview" data-filter="true"></ul>
</div>      

</div>

<script src="js/jquery.js"></script>
<script src="js/jquery.mobile-1.0rc1.min.js"></script>
<script src="js/employeelist.js"></script>
<script src="js/employeedetails.js"></script>
<script src="js/reportlist.js"></script>

</body>

</html>

文件.js

enter code here 
var serviceURL = "http://localhost/services/";

var employees;

$('#employeeListPage').bind('pageinit', function(event) {
getEmployeeList();
});

function getEmployeeList() {
$.getJSON(serviceURL + 'getemployees.php', function(data) {
    $('#employeeList li').remove();
    employees = data.items;
    $.each(employees, function(index, employee) {
        $('#employeeList').append
('<li><a href="employeedetails.html?id=' + employee.id + '">' +
                '<h4>' + employee.lastName + '</h4>' +
                '<p>' + employee.title + '</p>' +
                '<span class="ui-li-count">' 
+ employee.reportCount + '</span></a></li>');
    });
    $('#employeeList').listview('refresh');
});
}

文件.php

<?php
include 'config.php';

$sql = "select e.id, e.lastName, e.title, count(r.id) reportCount " . 
    "from employee e left join employee r on r.managerId = e.id " .
    "group by e.id order by e.lastName";


try {
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);  
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->query($sql);  
$employees = $stmt->fetchAll(PDO::FETCH_OBJ);
$dbh = null;
echo '{"items":'. json_encode($employees) .'}'; 
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}'; 
}


?>

这是我的localhost database

"INSERT INTO employee    (id,firstName,lastName,managerId,title,department,officePhone,cellPhone,email,city,picture) VALUES (12,'Steven','Wells',4,'Software Architect','Engineering','617-000-0012','781-000-0012','swells@fakemail.com','Boston, MA','steven_wells.jpg')"

我想问我应该怎么做才能将我的代码修改为display简单"lastname,department,and title" only的,从我的数据库中webbrowser

4

1 回答 1

0
$sql = "select e.id, e.lastName, e.title, e.department, count(r.id) reportCount " . 
"from employee e left join employee r on r.managerId = e.id " .
"group by e.id order by e.lastName";

接着

('<li><a href="employeedetails.html?id=' + employee.id + '">' +
                '<h4>' + employee.lastName + '</h4>' +
                '<p>' + employee.title + '</p>' +
                '<p>' + employee.department + '</p>' +
                '</li>');
于 2013-05-03T10:59:05.090 回答