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 6919183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:57:26+00:00 2026-05-27T09:57:26+00:00

I have a query which returns some results, and then I’m using a while

  • 0

I have a query which returns some results, and then I’m using a while loop to output the results.

The problem I’m having is that I want to return the ‘question’ before the while loop so that it doesn’t display a number of times inside the loop.

I have the following code:

$query  = "SELECT * FROM polls LEFT JOIN pollanswers ON polls.pollID = pollanswers.pollID WHERE polls.pollID = 1 ORDER By pollAnswerListing ASC";
$result = mysql_query($query);

echo '<p>Question</p>';
echo '<form action="#" class="poll-form">';
echo '  <p class="error"></p>';
echo '  <fieldset>';

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo '<div class="row">';
    echo '<input type="radio" name="poll" id="'.$row["pollAnswerID"].'" class="radio" value="'.$row["pollAnswerID"].'" /><label for="'.$row["pollAnswerID"].'">'.$row["pollAnswerValue"].'</label>';
    echo '</div>';
}

echo '  </fieldset>';
echo '</form>';

As you can see the loop is working perfectly, but how do I output the question just once from the same SQL statement BEFORE outputting the loop?

  • 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-05-27T09:57:27+00:00Added an answer on May 27, 2026 at 9:57 am

    You can fetch one row to display your question (assuming you have the same question value for multiple rows), then use mysql_data_seek() to rewind the result resource back to the first record to start your loop:

    // Retrieve the first row...
    $first_row = mysql_fecth_array($result, MYSQL_ASSOC);
    
    // Output your question however you need to...
    echo "whatever...";
    
    // Then rewind the result back to zero
    mysql_data_seek($result, 0);
    
    // Proceed with the rest of your while loop
    while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        echo '<div class="row">';
        echo '<input type="radio" name="poll" id="'.$row["pollAnswerID"].'" class="radio" value="'.$row["pollAnswerID"].'" /><label for="'.$row["pollAnswerID"].'">'.$row["pollAnswerValue"].'</label>';
        echo '</div>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, so I have an SQLS db that I want to query using some
I have a query which returns a series of cells of data from a
I have a linq query which returns the ID of a question based on
I have an Informix SQL query which returns a set of rows. It was
i've got a SQL query which returns multiple rows, and i have : $data
If I have a function which returns a reference cursor for a query, how
We have some search functionality that can return tens of thousands of results from
I have a view that returns 2 ints from a table using a CTE.
I am making an SQL query in which I want to get some results
Say I have a query which returns the following result: | val | type

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.