0

我是 PHP 新手,我的代码有问题。我有两张桌子:

seeker

seeker_nic | username
-----------+----------
111        | ali
222        | umer
333        | raza

bloodrequest

id | seeker_nic | requireddate
---+------------+--------------
1  | 111        | 2012/9/9
2  | 222        | 2012/5/8
3  | 111        | 2012/10/11
4  | 111        | 2012/11/12
5  | 222        | 2012/7/9
6  | 333        | 2012/4/4

现在我想列出一次最大日期的用户,比如..

s.no | username | requireddate
-----+----------+--------------
1    | ali      | 2012/11/12
2    | umer     | 2012/7/9
3    | raza     | 2012/4/4

我正在使用这个查询...

select seeker.username, max(bloodrequest.requireddate)
from seeker
join bloodrequest on seeker.seeker_nic=bloodrequest.seeker_nic
group by seeker.username

此查询在 phpMyAdmin 中有效,它显示了我想要的结果。但是当我在 PHP 中运行这个查询时,requireddate 列发生了错误:

"Undefined index: requireddate in C:\wamp\www\list.php on line 64"

第 64 行是:

<td><?php echo $rec['requireddate']; ?></td>

谁能告诉我问题出在哪里

4

1 回答 1

4
select seeker.username, max(bloodrequest.requireddate) as requireddate
from seeker
join bloodrequest on seeker.seeker_nic=bloodrequest.seeker_nic
group by seeker.username

那么应该工作。您需要为该列指定所需的名称。

于 2012-04-04T19:54:09.940 回答