I want to put this in a table so I can repeat this twice in two cell.

$intNumber = 1;
$sql=correctanswer($_SESSION['username1'], $_SESSION['smodule']);

	echo "<strong>the ones are ticked is right answer </strong></td><br />\n";
 
      while($info = mysql_fetch_array( $sql)) {
  
      echo " <strong>$intNumber, {$info['Que_Question']} </strong><br />\n";
      
       
  
      
  
      for($i = 1; $i <= 4; $i++) {
  
     echo "<input type=\"checkbox\" name=\"choice{$i}[]\"";
		
  
      
      echo    ( $info['Ans_Answer'.$i]) ? " checked" : "";

       
  
      
      
  
     
	  echo ($info['Que_Answer'.$i]) ? " style=\"border: 1px solid #0f0;\" " : "";
       
  
     echo " /> {$info['Que_Choice'.$i]} <br />\n";

     }
	  
  
      $intNumber++;
  
      }

Dani AI

Generated

asked to render the same question block twice side-by-side; rightly asked about the correctanswer routine — make sure that function returns a usable result (an array or statement you can iterate twice). A reliable pattern is: fetch all rows into an in-memory array, then render that array into two table cells. That avoids re-running the query and lets you give each cell unique input names so POST data does not collide.

A compact example using PDO (adapt field names to your schema):

$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // fetch once

function renderColumn($rows, $side) {
  echo '<td>';
  foreach ($rows as $q) {
    echo '<strong>'.htmlspecialchars($q['question_text']).'</strong><br>';
    for ($i = 0; $i < 4; $i++) {
      $name = 'choice['.$q['id'].']['.$side.']['.$i.']'; // keeps names unique per column
      $checked = !empty($q['correct'][$i]) ? ' checked' : '';
      echo '<input type="checkbox" name="'.$name.'" value="'.$i.'"'.$checked.'> '
           .htmlspecialchars($q['choices'][$i]).'<br>';
    }
  }
  echo '</td>';
}

echo '<table><tr>';
renderColumn($rows, 'A');
renderColumn($rows, 'B');
echo '</tr></table>';

Notes and cautions: escape all output with htmlspecialchars, use PDO or mysqli with prepared statements instead of deprecated mysql_* functions (see PDO/mysqli docs), and decide whether both visual copies should submit input. If the second copy is visual only, render it with disabled inputs or clone the first via CSS/JS instead of duplicating names. For prepared-statement examples, see the PHP manual: mysqli prepared statements quickstart.

Where is the correctanswer function? What are your specs and how do you think to work?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.