Я пытаюсь повторить такую ​​форму:

          1   2   3
Question (o) (o) (o)
Question (o) (o) (o)

Но я получаю это:

             1   2   3
  Question  (o) (o) (o)
             1   2   3
  Question  (o) (o) (o)

.

     if ($result) {
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $body = $row['question_body'];
    $question_id = $row['question_id'];
        echo '<div class="questions-1">';
        echo '  
        <table width="auto" border="0">
          <tr>
            <td>&nbsp;</td>
            <td class="answer_value">1</td>
            <td class="answer_value">2</td>
            <td class="answer_value">3</td>
          </tr>
          <tr>
            <td class="question">'.$body.'</td>
            <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="0"></td>
            <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="1"></td>
            <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="2"></td>
          </tr>
        </table>';      
         echo '</div>';  
0
user3906056 23 Авг 2014 в 00:56

2 ответа

Лучший ответ
<!-- try to not echo big chunk of text, instead remove them out of the php section of code -->
<div class="questions-1">  
        <table width="auto" border="0">
            <tr>
                <td>&nbsp;</td>
                <td class="answer_value">1</td>
                <td class="answer_value">2</td>
                <td class="answer_value">3</td>
              </tr>
    <?php
    if ($result) {
    while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
        $body = $row['question_body'];
        $question_id = $row['question_id'];
              echo '<tr>
                <td class="question">'.$body.'</td>
                <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="0"></td>
                <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="1"></td>
                <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="2"></td>
              </tr>';
    }
    ?>
   </table></div>
5
Dany Balian 22 Авг 2014 в 21:04

Попробуйте напечатать заголовок перед оператором while

        <td class="answer_value">1</td>
        <td class="answer_value">2</td>
        <td class="answer_value">3</td>
0
Mamoum Elsir 22 Авг 2014 в 20:59