[Solved] PHP Get 2 data rows in single iteration [closed]


First get all data into an array. Then compose that array multidimensional array. So you can push two rows in every single key something like that.

while($row = mysql_fetch_assoc($query)){
  $data[] = $row;
}

$last_data = array();
$key = 0;
for($i=0;$i<sizeof($data);$i++) {
  if($i%2 == 0)
  {
    $key++;
  } 
  $last_data[$key][] = $data[$i]; 
}

Then you can iterate over html table.

<?php foreach ( $last_data as $key => $row) { ?>
<tr>
    <?php foreach ( $row as $k => $row1) { ?>
    <td> <?php echo $row1['field'] ?></td>
    <?php } ?>
</tr>
<?php } ?>

( Suggestion Use mysqli_* instead of mysql_* for keep your code using deprecated extensions. )

1

solved PHP Get 2 data rows in single iteration [closed]