Jump to content

Retrieve last record of each group in a table


abdur_afzal

Recommended Posts

Hi,

 

I want to retrieve last record of each group. I am using the following qury and it is giving me the last record of the table not each group.

 

$sql="SELECT * FROM $tbl_name ORDER by a_datetime DESC LIMIT 1";

$result=mysql_query($sql);

<?php

while($rows=mysql_fetch_array($result)){ // Start looping table row

?>

Any help will be appreciated.

 

Thanks

Table forum_question

CREATE TABLE `forum_question` (

`id` int(4) NOT NULL auto_increment,

`topic` varchar(255) NOT NULL default '',

`detail` longtext NOT NULL,

`name` varchar(65) NOT NULL default '',

`email` varchar(65) NOT NULL default '',

`datetime` varchar(25) NOT NULL default '',

`view` int(4) NOT NULL default '0',

`reply` int(4) NOT NULL default '0',

PRIMARY KEY (`id`)

) TYPE=MyISAM AUTO_INCREMENT=1 ;

 

Table forum_answer

CREATE TABLE `forum_answer` (

`question_id` int(4) NOT NULL default '0',

`a_id` int(4) NOT NULL default '0',

`a_name` varchar(65) NOT NULL default '',

`a_email` varchar(65) NOT NULL default '',

`a_answer` longtext NOT NULL,

`a_datetime` varchar(25) NOT NULL default '',

KEY `a_id` (`a_id`)

) TYPE=MyISAM;

 

What i basically want is the last answer of each question from the "forum_answer" table.

 

Thanks very much.

I apologize for that. I was trying to modify my first post because I posted the whole code. So i thought may be by posting in short form will help.

 

This is my first post ever in a forum, and I don't know much about PHP.

 

I will really appreciate your help.

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.