why query working on phpmyadmin but not in php page

Go To StackoverFlow.com

0

I am new to PHP and I have a problem in my code. I have two tables:

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

Now I want to list users one time with maximum date like..

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

I am using this query...

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

This query works in phpMyAdmin, it shows the result that I wanted. But when I run this query in PHP an error occured on requireddate column:

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

Line 64 is:

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

Can anyone please tell me where is the problem

2012-04-04 19:52
by maham
Please include your php code that is calling your mysql query / populating your $rec array - Blake 2012-04-04 19:54


4

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

should work then. you need to give the column the name you want.

2012-04-04 19:54
by binarious
this is correct, but for an explanation: max(bloodrequest.requireddate) would be the column name as that is what you are selecting. by using as requireddate, you are re-naming that to requireddate so it will be $rec['requireddate'] when you are in php - Jonathan Kuhn 2012-04-04 19:58
OMG it workeddd.. thank youu sooooooo muchhh !!!! :) :) u have solved my problem .. thnx once again..: - maham 2012-04-04 20:04
JonathanKuhn thanks for the addition. @mahan good to hear that : - binarious 2012-04-04 20:06
@maham If an answer was provided, don't forget to mark it as the answer - Blake 2012-04-04 20:12
Ads