|
Posted by J.O. Aho on 02/12/06 02:25
Beshoo wrote:
> hi
> I have this function to print each question and it`s answar / actually
> from 2 tables answers and questions /
>
> I am taking the "question id" to be the "answer parent_id",so that I
> can know each question and its answers..... ok!!
>
> the quey like this:
>
> function display (){
> $sql="SELECT * from answers,questions WHERE
> answers.parent_id=questions.question_id";
> $exe=mysql_query($sql);
> while ($row=mysql_fetch_assoc($exe))
> {
> echo $row['answer']."<br>";
> echo $row['quest']."<br>";
>
> }
> }
> display();
>
> the problem is.. in this way the question will be printed more than one
> time , in another word the questios will be printed each time its
> answer printed !!!
>
> SO how I can print the question just one time???!!!
> pleeeez !!!
> thank you very much my frnds !!!
>
You can use the DISTINCT option when you fetch the data from the database,
this way you will get just one line even if the are doublets.
If you have more than one answer to the same question, then I would suggest
you keep track of the question.id and compare it with the current
question.id, if it's the same then don't print the answer, if it's different,
then print and set the storage variable to the new question.id.
//Aho
[Back to original message]
|