这是我第一次介绍 NotORM,我无法打印外键数据。这是我的表:
**userinfo**
id , int (primary key, autoincrement)
username , varchar(50)
gender , varchar(6)
password , varchar(50)
**budgetinfo**
entryid , int (primary key, autoincrement)
userid int references userinfo(id)
amount , varchar(50)
entrydate , varchar(6)
这是我的 NotORM 代码:
<?php
require "NotORM.php";
$dsn = "mysql:dbname=budget;host=127.0.0.1";
$pdo = new PDO ( $dsn, "root", "root" );
$budgetdb = new NotORM ( $pdo );
?>
该代码列出了记录,但没有打印budgetinfo 条目。
我哪里出错了?
<br/><br/>
<hr/>
Listing records, userinfo(id) => pk , budgetinfo(userid) => fk
<hr/>
<?php
$userinfos = $budgetdb->userinfo();
if(isset($userinfos) && count($userinfos)>0){
foreach ( $userinfos as $userinfo ) {
echo $userinfo ["username"] . " " . $userinfo ["gender"] . "<br/>";
$budgets = $userinfo->budgetinfo();
if(isset($budgets) && count($budgets)>0){
foreach ($budgets as $budget)
echo $budget->budgetinfo["amount"] . " , " . $budget->budgetinfo["entrydate"] . "<br/>";
}
else
echo "No budgets set...";
echo "<br/>-------------------------------<br/>";
}
}
else
echo "No record found...";
?>