/home/banprang/domains/plai.go.th/public_html/coremain/module/question/question_detail.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
import_request_variables
('pG''p_');

$sel_q "select * from cms_question where id_sub = '$p_id_sub'";
$que_q mysql_query($sel_q);
$obj_q mysql_fetch_assoc($que_q);
$qid $obj_q['id_question'];

$navig['question&id_sub='.$p_id_sub] = $obj_q['topic'];
$navig['question_show&id_sub='.$p_id_sub.'&question='.$qid] = 'ผลสำรวจ';
$navig['question_detail'] = 'รายละเอียด';
navigator($navig);
echo
"<br>";
bar_header($obj_q['topic']); // Bar_Header
fieldset_top($obj_q['topic']);

# question_title
$array_title = array();
$sel_title "select * from cms_question_title where question_id = '$qid' and title_parent = '0' order by title_order";
$que_title mysql_query($sel_title);
while(
$obj mysql_fetch_assoc($que_title)){
  
$array_title[$obj['title_order']]['title'] = $obj;

  
# question_choice
  
$choice = array();
  
$sel_choice "select * from cms_question_choice where question_id = '$qid' and title_id = '$obj[title_id]' order by choice_order";
  
$que_choice mysql_query($sel_choice);
  while(
$_choice mysql_fetch_assoc($que_choice)){
    
$choice[$_choice['choice_order']] = $_choice;
  }
  
$array_title[$obj['title_order']]['choice'] = $choice;
}

# data_title
$sel_data "select * from cms_question_title where question_id = '$qid' and title_parent > '0' order by title_order";
$que_data mysql_query($sel_data);
while(
$obj mysql_fetch_assoc($que_data)){
  
$array_data[$obj['title_parent']][$obj['title_order']] = $obj;
}
$num_question count($array_title);


$row_per_page 1//กำหนดจำนวนบรรทัดต่อหน้า 
if (empty($p_startrow)) { //ลองตรวจดูว่าค่าแถวเริ่มต้นที่จะแสดงไม่ได้กำหนดหรือเปล่า ถ้าไม่ได้กำหนด จะกำหนดให้เป็น 0 
  
$startrow 0
}else{
  
$startrow $p_startrow;
}

$query="select * from cms_question_ansheader where question_id = '$qid' order by header_id desc";
$query_count="select count(header_id) from cms_question_ansheader where question_id = '$qid' order by header_id desc";
$result mysql_query($query_count); 
$row mysql_fetch_array($result); 

$total_row $row[0]; //ได้ค่าจำนวนบรรทัดทั้งหมดที่จะต้องแสดง 
$total_page intval((($total_row-1)/$row_per_page)+1); //หาค่าจำนวนหน้าทั้งหมดที่ต้องแสดง 
$current_page = (($startrow)/$row_per_page)+1//หาว่าหน้าที่แสดงอยู่ปัจจุบันเป็นหน้าที่เท่าไหร่ 

$array_header = array();
$sel_header $query." LIMIT $startrow,$row_per_page";
$que_header mysql_query($sel_header);
while(
$obj_header mysql_fetch_assoc($que_header)){
  
$arr explode('_'$obj_header['user_ip']);
  
$obj_header['ip_answer'] = $arr[0];
  
$array_header[$obj_header['header_id']] = $obj_header;
}
#debuga($array_header);

$array_answer = array();
$sel_answer "select * from cms_question_answer where question_id = '$qid'";
$que_answer mysql_query($sel_answer);
while(
$obj_answer mysql_fetch_assoc($que_answer)){
  
$arr explode('::'$obj_answer['answer']);
  if(
count($arr) > 1){
    
$obj_answer['answer'] = $arr[0];
    
$obj_answer['text_other'] = $arr[1];
  }
  
$array_answer[$obj_answer['header_id']][$obj_answer['title_id']] = $obj_answer;
}


if (
$total_page>1) { //ตรวจดูว่าถ้าจำนวนหน้าทั้งหมดมีไม่เกิน 1 หน้า ต้องแสดงบรรทัดที่จะให้เลือกหน้า 
  
$previous_page $current_page-1//หาว่าหน้าก่อนหน้าปัจจุบันคือหน้าอะไร 
  
$next_page $current_page+1//หาว่าหน้าถัดจากหน้าปัจจุบันคืออะไร 
  
if ($previous_page >0) { //ถ้าหน้าก่อนหน้าติดลบหรือเป็นศูนย์แสดงว่าไม่สามารถแสดงหน้าก่อนหน้าได้ 
    
$new_startrow $startrow $row_per_page 
    
$left_page_show '<a href="index.php?mod=question_detail&path=question&id_sub='.$p_id_sub.'&question='.$qid.'&startrow='.$new_startrow.'"><b>ก่อนหน้า</b></a>&nbsp;';
  } else { 
    
$left_page_show "<b>ก่อนหน้า</b>&nbsp;"
  } 
  if (
$next_page $total_page) { //ถ้าหน้าถัดไป มากกว่าจำนวนหน้าทั้งหมด แสดงว่าไม่สามารถแสดงหน้าถัดไปได้ 
    
$right_page_show "&nbsp;<b>ต่อไป</b>"
  } else { 
    
$new_startrow $startrow $row_per_page
    
$right_page_show '&nbsp;<a href="index.php?mod=question_detail&path=question&id_sub='.$p_id_sub.'&question='.$qid.'&startrow='.$new_startrow.'"><b>ต่อไป</b></a>';
  } 

  
$middle_page_show ""
  for (
$i=1;$i<=$total_page;$i++) { //วนลูปแสดงหน้าทั้งหมด 
    
if ($i == $current_page) { //ถ้าหน้าที่พิมพ์เป็นหน้าเดียวกับหน้าปัจจุบัน แสดงให้ไม่สามารถคลิ๊กได้ 
      
$middle_page_show .= "&nbsp;<font color='ff0000'><b>[$i]</b></font>&nbsp;"
    } else { 
      
$new_startrow = (($i-1)*$row_per_page); 
      
$middle_page_show .= '&nbsp;<b><a href="index.php?mod=question_detail&path=question&id_sub='.$p_id_sub.'&question='.$qid.'&startrow='.$new_startrow.'">'$i .'</a></b>&nbsp;';
    } 
  } 
  
$page_show $left_page_show $middle_page_show $right_page_show
} else { 
  
$page_show ""
}
?>
<font color='0000ff' class='Menu'><?= $page_show ?></font>
<br/><br/>

<?php if(count($array_header) == 0){ ?>
  <center><h4>- ยังไม่มีผลสำรวจ -</h4></center>
<?php }else{ ?>
  <?php foreach($array_header as $header_id => $header){ ?>
  <table width="97%" border="0" cellpadding="0" cellspacing="0" align="center">
    <tr>
      <td style="padding-bottom: 10px;" align="right">เมื่อวันที่ <?= $header['datetime'?></td><!--[IP : <?//= $header['ip_answer'] ?>]  ?>-->
    </tr>
  <?php
    
foreach($array_title as $title_order => $title){
      
$t_id $title['title']['title_id'];
      
$type $title['title']['type_id'];
      
$answer $array_answer[$header_id];
  
?>
    <tr>
      <td>
        <table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse: collapse;">
        <?php if($type == '1'){ ?>
          <tr bgcolor="#f0e8d0">
            <td colspan="2"><?= $title['title']['title_name'?></td>
          </tr>
          <?php if(isset($array_data[$t_id])){ foreach($array_data[$t_id] as $data_order => $data){ ?>
          <tr>
            <td width="50%">
              &nbsp;&nbsp;<?= $data_order ?><?= $data['title_name'?><?php echo $data['title_validate'] == '&nbsp;<span style="color: #ff0000">*</span>' '' ?>
            </td>
            <td width="50%">: <?= $answer[$data['title_id']]['answer'?></td>
          </tr>
          <?php }} ?>
        <?php }else if($type == '2'){ ?>
          <tr>
            <td>
              <table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse: collapse;">
                <tr bgcolor="#f0e8d0">
                  <td><?= $title['title']['title_name'?></td>
                  <?php foreach($title['choice'] as $order_choice => $choice){ ?>
                  <td width="10%" align="center"><?= $choice['choice_name'?></td>
                  <?php ?>
                </tr>
              <?php
                
if(isset($array_data[$t_id])){
                  foreach(
$array_data[$t_id] as $data_order => $data){
              
?>
                <tr>
                  <td style="text-indent: 20px;"><?= $data_order ?><?= $data['title_name'?></td>
                  <?php foreach($title['choice'] as $order_choice => $choice){ ?>
                    <td align="center"><?= $answer[$data['title_id']]['answer'] == $choice['choice_id'] ? '/' '' ?></td>
                  <?php ?>
                </tr>
              <?php }} ?>
              </table>
            </td>
          </tr>
        <?php }else if($type == '3' || $type == '4'){ ?>
          <tr>
            <td>
              <table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse: collapse;">
                <tr bgcolor="#f0e8d0">
                  <td><?= $title['title']['title_name'?></td>
                </tr>
              <?php
                
if(isset($array_data[$t_id])){
                  foreach(
$array_data[$t_id] as $data_order => $data){
                    if(
$data['title_id'] == $answer[$t_id]['answer']){
              
?>
                <tr>
                  <td style="text-indent: 20px;"><?= $data['title_name'?> <?= isset($answer[$t_id]['text_other']) ? '('.$answer[$t_id]['text_other'].')' '' ?></td>
                </tr>
              <?php }}} ?>
              </table>
            </td>
          </tr>
        <?php }else if($type == '5'){ ?>
          <tr bgcolor="#f0e8d0">
            <td><?= $title['title']['title_name'?></td>
          </tr>
          <tr>
            <td style="text-indent: 20px;"><?= $answer[$t_id]['answer'?></td>
          </tr>
        <?php }else if($type == '6'){ ?>
          <tr bgcolor="#f0e8d0">
            <td><?= $title['title']['title_name'?></td>
          </tr>
          <?php
            
if(isset($array_data[$t_id])){
              foreach(
$array_data[$t_id] as $data_order => $data){
          
?>
            <tr>
              <td style="text-indent: 20px;"><?= $data['title_name'?></td>
            </tr>
          <?php }
            }
          
?>
        <?php ?>
        </table>
      </td>
    </tr>
  <?php ?>
  </table>
  <hr/>
  <?php ?>
<?php 
?>