Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7897601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:12:29+00:00 2026-06-03T08:12:29+00:00

I have a working survey that pulls each question and any related answers from

  • 0

I have a working survey that pulls each question and any related answers from multiple tables. Each question is stored in the following table:

  • tblQuestions, with the fields:
  • qID
  • qText.

The related answers are stored in the table:

  • tblPossAnswers, with the fields:
  • aID
  • qID
  • answerText.

So, I would have 3 possible answers for each question. My sql to pull everything is:

select * from tblQuestions, tblPossAnswers where
tblPossAnswers.qID = tblQuestions.qID
order by tblQuestions.qID ASC

And my PHP to display it:

while ($row = mysql_fetch_array($result)) {

echo "<p>" . $row['qText'] . "</p><br />";
echo "<input type='radio' name='".$row['qID']."' value='".$row['aID']."' />";
echo $row['answerText'];
}

The problem is this is displaying the qText every time it displays a possible answer. So it looks like:

  • Question 1
  • Possible answer 1
  • Question 1
  • Possible answer 2
  • Question 1
  • Possible answer 3
  • Question 2
  • Possible answer 1
  • Question 2
  • Possible answer 2
  • Question 2
  • Possible answer 3

What I would like to do is have the qText only display when the first possible answer is pulled. I’m still somewhat of a newb to MySQL, so the solution might be something very simple that I’m just not seeing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:12:31+00:00Added an answer on June 3, 2026 at 8:12 am

    You can either test for whether the question has changed within your PHP loop:

    while ($row = mysql_fetch_array($result)) {
      if ($row['qID'] != $lastQuestionID) {
        echo "<p>" . $row['qText'] . "</p><br />";
        $lastQuestionID = $row['qID'];
      }
      echo "<input type='radio' name='".$row['qID']."' value='".$row['aID']."' />";
      echo $row['answerText'];
    }
    

    Or else you can group the MySQL results by question using GROUP_CONCAT, specifying a separator on which you then split the answers in PHP:

    select *, group_concat(answerText separator char(30)) as answers
    from tblQuestions join tblPossAnswers using (qID)
    group by tblQuestions.qID
    order by tblQuestions.qID ASC
    

    Then:

    while ($row = mysql_fetch_array($result)) {
      echo "<p>" . $row['qText'] . "</p><br />";
      foreach (explode(chr(30), $row['answers']) as $answer) {
        echo "<input type='radio' name='".$row['qID']."' value='".$answer."' />";
        echo $answer;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a working form that looks like the following =form_for @survey
I'm working on a small project that displays answers for a survey. I'm having
I have a working dropdown box that gives the answers yes & no. When
I'm working on a survey system for my company and I have it setup
I have working website in PHP with a MySQL backend which has several tables
I have working registration script the only problem is that i do not know
There are databases on Firebird and SQL Server. I have working stored procedure in
Have been working on this question for a couple hours and have come close
I am working on a survey application. I have a sql server database holding
I have a bunch of optional write-in values for a survey I'm working on.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.