在UBUNTU 10.04上使用Eclipse 3.5.2(PDT,WEB工具,APTANA 2和使用XDEBUG进行调试)...
我无法弄清楚这个代码有什么问题。我作为.NET开发人员已经工作多年了,所以我想我知道如何阅读文档和配置基本应用程序,尽管我是LAMP的新手。
以下页面仅显示“PHP正在运行”以及“我”,“您”和“她”的第一个列表。我通过登录PhpMyAdmin双重检查了数据库凭据。
调试时,我进入core_db.php,变量全部列为<Uninitialized>
,一切都停在$stmt->execute();
行
list_users.php
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php include 'db/chore_db.php' ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=encoding">
<title>Insert title here</title>
</head>
<body>
<?php echo 'Php is running'; ?>
<ul>
<?php $ar = array('me','you','her');
foreach ($ar as $user) {
?>
<li><?php echo $user;}?></li>
</ul>
<div>
<?php
$db = new chore_db();
$myusers = $db->get_users(null,null);
foreach ($myusers as $u) {
?>
<ul>
<li><?php echo $u; }?></li>
</ul>
</div>
</body>
</html>
chore_db.php
<?php
class chore_db{
/**
* @param int $id
* @param string $user_name
* @return Ambigous <multitype:, usersTbl>
*/
public function get_users($id, $user_name){
$users = array();
$sql = '';
$con = null;
$sql = 'SELECT id, chore_type, name, description, created_dt, created_by, modified_dt, modified_by FROM chores';// where id = IFNULL(?,id) and name = IFNULL(?,name)";
$con = new mysqli('localhost','chore_admin','!chore_admin','chores');
$stmt = $con->prepare($sql);
//bind parameters
//$stmt->bind_param('ss', $id_param, $name_param);
//$id_param = $id;
//$name_param = $user_name;
//execute the sql
$stmt->execute();
//now bind the results to variables
$stmt->bind_result($rs_id, $rs_chore_type, $rs_name, $rs_description, $rs_created_dt, $rs_created_by, $rs_modified_dt, $rs_modified_by);
while($stmt->fetch()){
$users[] = new usersTbl($rs_id, $rs_chore_type, $rs_name, $rs_description, $rs_created_dt, $rs_created_by, $rs_modified_dt, $rs_modified_by);
}
return $users;
}
}
class usersTbl{
public $id;
public $user_name;
public $first_name;
public $last_name;
public $created_dt;
public $created_by;
public $modified_dt;
public $modified_by;
public $user_chore_list;
public $user_chore_date_list;
//public function __construct(){}
public function __construct($userId, $uName, $fName, $lName, $createdDT, $createdDT, $createdBY, $modifiedDT, $modifiedBy){
$this->id = $userId;
$this->user_name = $uName;
$this->first_name = $fName;
$this->last_name = $lName;
$this->created_by = $createdBY;
$this->created_dt = $createdDT;
$this->modified_by = $modifiedBy;
$this->modified_dt = $modifiedDT;
}
}
答案 0 :(得分:1)
问题是您正在尝试回显对象,而没有说明应如何格式化其内容。你应该仍然得到一些输出,所以显然还有其他东西在发生,但这里有一个版本已修复很多问题:
<强> list_users.php 强>
<?php include 'db/chore_db.php' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=encoding">
<title>Insert title here</title>
</head>
<body>
<?php echo 'Php is running'; ?>
<ul>
<?php
$ar = array('me','you','her');
foreach ($ar as $user) {
?>
<li><?php echo $user; ?></li>
<?php } ?>
</ul>
<div>
<ul>
<?php
$db = new chore_db();
$myusers = $db->get_users(null,null);
foreach ($myusers as $u) {
?>
<li><?php echo $u->user_name; ?></li> <!-- You need to echo a property of the object (or several, rather than the object itself... -->
<?php } ?>
</ul>
</div>
</body>
</html>
答案 1 :(得分:0)
<ul>
<?php $ar = array('me','you','her');
foreach ($ar as $user) {
?>
<li><?php echo $user;}?></li> <<< this is at least one of the problems
</ul>