Jump to content

[SOLVED] View records in 3 column format


andz

Recommended Posts

i already asked this question yesterday on how to view records in 3 column format. i only asked that time a simple view of records.

 

here's the code yesterday that will allow me to view records in simple view (3 column format)

 

<?php

$show = range(1,15);

 

foreach ($show as $i => $data) {

  echo $data;

 

  if (($i + 1) % 3 == 0) {

      echo ' \n';

  } else {

      echo ' | ';

  }

}

?>

 

 

i need a code to view this kind of result in a table format. 3 column format also.

 

just replace the '\n' with break line "br"

Link to comment
https://forums.phpfreaks.com/topic/105102-solved-view-records-in-3-column-format/
Share on other sites

it's easier to use 2 variables in your loop. something like this:

 

$show = range(1,15);

$array_length = count($show);

 

echo '<table>';

 

for ($i = 0, $k = 1; $i < $array_length; $i++, $k++) {

  if ($k == 1) echo '<tr>';

 

  echo '<td>'.$show[$i].'</td>';

 

  if ($k == 3 || ($i + 1) == $array_length) {

      echo '</tr>';

      $k = 0;

  }

}

 

echo '</table>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.