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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:51:56+00:00 2026-06-05T22:51:56+00:00

I have a query mysql_select_db($database_auditing, $auditing); $query_sections3 = sprintf(SELECT tblanswer.questionid AS answerqid, tblanswer.answerid AS

  • 0

I have a query

mysql_select_db($database_auditing, $auditing);
$query_sections3 = sprintf("SELECT tblanswer.questionid AS answerqid,
                                tblanswer.answerid AS answerid, 
                                tblanswer.answer AS answer, 
                                tblquestion.questionid AS questionid, 
                                tblquestion.questiontext AS questiontext, 
                                tblquestion.questionid AS quesid, 
                                tblquestion.questiontypeid AS questiontype, 
                                tblquestion.sectionid AS sectionid, 
                                tblscore.score1 AS score1, 
                                tblscore.score2 AS score2, 
                                tblscore.score3 AS score3, 
                                tblscore.score3 AS score3, 
                                tblscore.score4 AS score4, 
                                tblhelptext.helptext AS help, 
                                tblsection.sectionname AS sectionname 
                            FROM tblanswer 
                            LEFT JOIN tblquestion ON tblanswer.questionid = tblquestion.questionid 
                            LEFT JOIN tblscore ON tblquestion.questionid = tblscore.questionid 
                            LEFT JOIN tblhelptext ON tblquestion.questionid = tblhelptext.questionid 
                            LEFT JOIN tblsection ON tblquestion.sectionid=tblsection.sectionid 
                            WHERE tblanswer.auditid=%s 
                            ORDER BY tblquestion.sectionid",  
                        GetSQLValueString($_SESSION['auditid'], "int"));

$sections3 = mysql_query($query_sections3, $auditing) or die(mysql_error());

$totalRows_sections3 = mysql_num_rows($sections3);

which pulls relevant questions from the database and builds a questionnaire relevant to the site.

Each question is relevant to a certain section.

So what I’m trying to do (and failing at miserably) is to get the results from the query above to appear in the relevant part of the accordion I’m using for the questionnaire without having to use a nested query within each div (which is causing me issues with entering the given results into the db).

Thanks to everyone who contributed to this post.

I have managed to get the accordion to siplay each question within it’s own tab but what I’m trying to achieve is to get all the relevant questions within same tab.

Here’s the accordion code:

<?php $prevsub='';
$purpleronnie=0;
 while ($row_sections3=mysql_fetch_assoc($sections3)) {

     if ($row_sections3['sectionid'] !=$prevsub) {
         ?>

<div class="AccordionPanel">
<div class="AccordionPanelTab"><?php echo $row_sections3['sectionname'];?></div>
<div class="AccordionPanelContent">

<br />
<h5>Please answer the questions below to the best of your ability. For help, hover over the help icon, help text will appear in the box to the right of the screen.</h5>
<?php }?>

<table class="table2" align="center">
<tr>

<th><?php echo $row_sections3['questiontext'];?> <input type="hidden" name="qnumber[]" value="<?php echo $row_sections3['questionid'];?>" />
</th>
<td>
<input type="text" name="answerid[<?php echo $purpleronnie;?>]" value="<?php echo  $row_sections3['answerid'];?>" size="1" />

<?php if ($row_sections3['questiontype']=="1") { ?> 
<input type="text" size="25" name="answer[<?php echo $purpleronnie;?>]" value="<?php echo $row_sections3['answer'];?>" />

<?php } ?>

</table>    

</div>
</div>
<?php $purpleronnie++;
 if ($prevsub!=''&&$prevsub!=$row_sections3['sectionid'])
 $prevsub=$row_sections3['sectionid']; }?>

Any suggestions of how to alter the above to get the accordion div’s to change everytime the section id increases, rather than for every question?

Many thanks
Dave

  • 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-05T22:51:57+00:00Added an answer on June 5, 2026 at 10:51 pm

    If you are able to sort the stuff by section id then you can build an array of data sectioned off by the section_id first and then you would loop through that and build your divs etc. The code below is based on your example code and prob not the most elegant but it will do what you want granted the data comes in as assumed. If this is not 100% what you need it will at least give you a place to start. Also, be careful with your closing tags. You missed closing your table column and row in the example code you posted.

    $purpleronnie=0;
    $data = array();
    
    // sort your questions into "buckets" first
    while ($row_sections3=mysql_fetch_assoc($sections3)) {
        // store that row of data in the correct sectioned off container
        $data[$row_sections3['sectionid']][] = $row_sections3;
    }
    
    // do nothing if we have no data! 
    if(empty($data)) exit('woops! no results in this section!');
    
    // now loop through these results and build your divs
    echo '<div class="AccordionPanel">';
    
    foreach($data as $sectionid => $rows){
        // grab the section name of the first row to use for the main section tabs
        $section_name = $rows[0]['sectionname'];
        echo 
            '<div class="AccordionPanelTab">'.$section_name.'</div>
             <div class="AccordionPanelContent">
                <br />
                <h5>Please answer the questions below to the best of your ability. 
                    For help,hover over the help icon, help text will appear in the 
                    box to the right of the screen.</h5>
                <table class="table2" align="center">';
    
        // now just loop through the rows in this section and fill in the stuff
        foreach($rows as $row){
          echo 
              '<tr>
                   <th>'.$row['questiontext'].'
                       <input type="hidden" name="qnumber[]"
                              value="'.$row['questionid'].'"/>
                   </th>
                   <td>
                       <input type="text" name="answerid['.$purpleronnie.']" 
                              value="'.$row['answerid'].'" size="1" />';
    
            // do your conditional here
            if($row['questiontype']=="1") {
                echo '<input type="text" size="25" name="answer['.$purpleronnie.']" 
                             value="'.$row['answer'].'" />';
            }
    
            // make sure you close your rows!
            echo '</td></tr>';
        } // end foreach row of questions
    
        // close of question table and accordion panel content
        echo '</table></div>';
    
        // increment your counter thing
        ++$purpleronnie; 
    }// end foreach sectionid
    
    // close the accordian panel container
    echo '</div>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query: mysql_select_db('scanner'); $query = SELECT * FROM scanner.proxy ORDER BY RAND()
I have the next mysql query: $productn = $jdb->query('SELECT t2.title FROM '.DB_PREFIX.'shopping_cart AS t1
I have a mysql query Select * from tbl_schoolphotos where Filename like 'glasshouse_1_%' order
I have a MySQL query SELECT * FROM 'redirect' WHERE 'user_id'= \''.$_SESSION['user_id'].' \' ORDER
I have a mysql query like this: $topicreplycount = mysql_query('SELECT COUNT(DISTINCT post_msg_id) FROM phpbb_attachments
So, I have this mysql query: SELECT member_id, text FROM review WHERE text !=
I have the following MySQL-query: SELECT s.student_socialnr, s.student_lastname, s.student_firstname, cs.city_name, scp.cpl_startdate, scp.cpl_enddate, scp.cpl_invoice, cu.customer_name,
Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
I have these 2 statements: $pow= mysql_query(select options.label from options where userid='1'); and: $sql=(SELECT

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.