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
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.