2012-06-18 2 views
0

을 변경 내가 쿼리 데이터베이스에서 관련 질문을 가져와 사이트와 관련된 설문을 작성표시 쿼리 결과 섹션 ID가

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); 

에게 있습니다.

각 질문은 특정 섹션과 관련이 있습니다.

그래서 내가 뭘하려는 (그리고 비참하게 실패) 위의 쿼리에서 중첩 된 쿼리를 사용하지 않고 설문지에 사용하고있는 아코디언의 관련 부분에 나타나는 결과를 얻는 것입니다 각 div 내에서 (주어진 결과를 DB에 입력하는 데 문제가 있음).

this post에 기고 한 모든 분들께 감사드립니다.

나는 아코디언을 각자의 탭 내에서 섞어서 만들었지 만, 나는 달성하기 위해 노력하고있는 것은 동일한 탭 내에서 관련된 모든 질문을 얻는 것이다. 아코디언 DIV 년대 오히려 모든 질문보다 매번 섹션 ID 증가, 변경 얻을 위를 변경하는 방법에

<?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']; }?> 

어떤 제안 :

여기에 아코디언 코드는?

많은 감사 데이브

답변

0

당신은 당신이 SECTION_ID 처음으로 해제 구분 데이터의 배열을 구축 할 수 있습니다 섹션 ID로 물건을 분류 한 다음 그 통해 루프 것 등 귀하의 div를 구축 할 수있는 경우 아래의 코드는 예제 코드와 prob를 기반으로하지만 가장 우아하지는 않지만 데이터가 정상적으로 제공되도록하려는 것입니다. 이것이 100 %가 아니라면 적어도 시작할 장소를 제공 할 것입니다. 또한 종료 태그를주의하십시오. 게시 한 예제 코드에서 테이블 열과 행을 닫지 못했습니다. 가 훌륭하게 작동 조정의 비트 (그리고 누락 된 세포/행 엔딩 미안, 나는 기차에 도착하려고 서둘러 게시 된로 -

$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

안녕 EmmanuelG는 당신에게 당신의 응답을 많이 감사합니다! –

관련 문제