how to display rows in Columns

It is for static page, dynamic page, website, SEO, performance and other web development discussion
Posts: 427
Joined: Sat Aug 23, 2014 5:34 pm

how to display rows in Columns

Postby ramverma » Wed Oct 07, 2015 4:49 pm


I have fingerprint records. Some days, the staff will have two punches, somes days three punches and some days more.

Each fingerprint comes as a single row like this:

dd/mm/yyyy HH:mm:ss

I want to display it as columns so date will be columns 1 and each punch in that day will be as a column similar.

How can I do this please?

Posts: 54
Joined: Sun Aug 30, 2015 8:01 am

Re: how to display rows in Columns

Postby sidbhatt » Thu Oct 08, 2015 4:46 am

try this,

foreach($records as $key => $row) {
foreach($row as $field => $value) {
$recNew[$field][] = $value;
//This creates a new array composed/transposed with the field names as keys and
//the "rowed" values as sub-arrays.

echo "<table>\n";

foreach ($recNew as $key => $values) // For every field name (date,f1,f2,f3,f4,f5,f6)
echo "<tr>\n"; // start the row
echo "\t<td>" . $key . "</td>\n" ; // create a table cell with the field name
foreach ($values as $cell) // for every sub-array iterate through all values
echo "\t<td>" . $cell . "</td>\n"; // write cells next to each other
echo "</tr>\n"; // end row


echo "</table>";

Return to “PHP, HTML, MYSQL and Web Hosting”

Who is online

Users browsing this forum: No registered users and 1 guest