abdur_afzal Posted December 1, 2009 Share Posted December 1, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/183541-retrieve-last-record-of-each-group-in-a-table/ Share on other sites More sharing options...
trq Posted December 1, 2009 Share Posted December 1, 2009 What does your table structure look like? Quote Link to comment https://forums.phpfreaks.com/topic/183541-retrieve-last-record-of-each-group-in-a-table/#findComment-968756 Share on other sites More sharing options...
abdur_afzal Posted December 1, 2009 Author Share Posted December 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/183541-retrieve-last-record-of-each-group-in-a-table/#findComment-968758 Share on other sites More sharing options...
trq Posted December 1, 2009 Share Posted December 1, 2009 Considering you've posted this question in several different places, your on your own I'm afraid. I'm done. Quote Link to comment https://forums.phpfreaks.com/topic/183541-retrieve-last-record-of-each-group-in-a-table/#findComment-968759 Share on other sites More sharing options...
abdur_afzal Posted December 1, 2009 Author Share Posted December 1, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/183541-retrieve-last-record-of-each-group-in-a-table/#findComment-968760 Share on other sites More sharing options...
Daniel0 Posted December 1, 2009 Share Posted December 1, 2009 This is my first post ever in a forum, and I don't know much about PHP. You would have known if you'd read our rules. 13. Duplication of topics is strictly prohibited. Quote Link to comment https://forums.phpfreaks.com/topic/183541-retrieve-last-record-of-each-group-in-a-table/#findComment-968829 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.