View unanswered posts | View active topics It is currently Mon Oct 02, 2023 3:42 pm



Reply to topic  [ 2 posts ] 
 multiple rows and one row 
Author Message
Junior Member

Joined: Sun Feb 08, 2009 11:58 am
Posts: 7
Post multiple rows and one row


Tue Sep 08, 2009 6:10 am
Report this post
Profile
Junior Member

Joined: Sun Feb 08, 2009 11:58 am
Posts: 7
Post 
Hi everyone!

The tables given below shows that every rows in the 'questions' table is assigned to four rows in the 'answers' table. I wonder how to select randomly four questions and sixteen answers and then display them separately. I want to gain the following effect:

first site:
1 question - 1 answer
- 1 answer
- 1 answer
- 1 answer

second site:
3 question - 3 answer
- 3 answer
- 3 answer
- 3 answer

third site:
2 question - 2 answer
- 2 answer
- 2 answer
- 2 answer

fourth site:
4 question - 4 answer
- 4 answer
- 4 answer
- 4 answer

If I write this query:
SELECT question FROM questions WHERE epoch_id = 2 AND id = 4;
then the result is:
question number 4

If I write this query:
SELECT answer FROM questions JOIN answers ON questions.epoch_id = 2 AND questions.id=answers.question_id AND answers.question_id = 4;
then the result is four times:
answer number 4
answer number 4
answer number 4
answer number 4

What do I have to do if I want to gain more rows from the 'answers' table?

Please help.
Thanks in advance for yours reply.


BELOW TABLE - structure
1. TABLE epochs: epoch, date_, refer_to_picture, title_picture, author_picture;
2. TABLE questions: epoch_id, question, date_;
3. TABLE answers: question_id, answer, boolean_type, date_;


Thu Sep 10, 2009 4:30 pm
Report this post
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.