1

Say you got a table view like this

seed_id     name           country
-------     ----------     -------

1           John           America
2           Jose           Mexico
3           Khan           Pakistan

and you'd like to paint the HMTL vertically as follows;

seed_id     1             2           3
name        John          Jose        Khan
country     America       Mexico      Pakistan

This kind of view comes very handy in two cases.

You want to print the table view or you want to compare fields side by side.

In print view, on a table with 50 fields, even printing a single record view does not get you a viewable print out. The paper will cut out the print proably at the 10th field or so.

but with a vertical view, it does not matter how many fields the table have.

Similarly, when you compare records side by side, like in this beautiful example

http://www.dpreview.com/products/compare/side-by-side?products=nikon_d90&products=nikon_d3&products=nikon_d4&sortDir=ascending

you get a very useful view.

I can sit down write this library function now but don't have the time at this moment. But I'm sure someone out there has either the time for it, or already has written it. Would you please share it please?

getview ($dbh,"select * from tableX where 1=1","vertical");

Average Joe
  • 4,521
  • 9
  • 53
  • 81

2 Answers2

7

You can use \G flag.

SELECT * FROM mytbl \G

UPD: sample article: http://slaptijack.com/software/enabling-vertical-g-output-in-the-mysql-client/

deadrunk
  • 13,861
  • 4
  • 29
  • 29
0

There's probably a better way that looping...

$table = array();
foreach($result_row as $row)
{
  foreach(array('seed_id','name','country') as $index)
  {
    $table[$index][] = $row[$index];
  }
}

Something like that should re-organise your array into the structure you'd need

Scuzzy
  • 12,186
  • 1
  • 46
  • 46