robert_gsfame Posted July 31, 2010 Share Posted July 31, 2010 i have two tables assume question and answer question table consists of Question_Date, Question_id and Question_title answer table consists of Answer_Date, Question_id, Answer_id and Answer_title let say i have 1000 records and i wish to display only the last 100 records combining both question and answer. How can i do this with loop..any suggestion would be appreciate thx Quote Link to comment https://forums.phpfreaks.com/topic/209406-loop-logical-problem/ Share on other sites More sharing options...
AbraCadaver Posted July 31, 2010 Share Posted July 31, 2010 Do it with the query not a loop: SELECT * FROM question, answer WHERE question.Question_id = answer.Question_id ORDER BY Answer_Date DESC LIMIT 100 Or ORDER BY Question_Date, not sure what you want. Quote Link to comment https://forums.phpfreaks.com/topic/209406-loop-logical-problem/#findComment-1093420 Share on other sites More sharing options...
robert_gsfame Posted July 31, 2010 Author Share Posted July 31, 2010 what if i want display all records from both table which Question_id is equal to 7 how can i do that with your query as i cant find anywhere to put the condition there :confused: Quote Link to comment https://forums.phpfreaks.com/topic/209406-loop-logical-problem/#findComment-1093421 Share on other sites More sharing options...
trq Posted July 31, 2010 Share Posted July 31, 2010 SELECT * FROM question, answer WHERE question.Question_id = answer.Question_id AND question.Question_id = 7 ORDER BY Answer_Date DESC LIMIT 100 Quote Link to comment https://forums.phpfreaks.com/topic/209406-loop-logical-problem/#findComment-1093476 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.