020 555 1111
  • Old fashion, modular, procedural PHP plus some scaffolding techniques to allow it to mimic MVC simplicity.
  • A quick reference to help you find in PHP maze what needs to be done and how to do it.
  • Learn a PHP Object Oriented Programming by building a live discussion forum application.
  • MVC - Model View Controller - real life, easy reference and application.
This product has options, take a look at them and select ones you like the most.
Options are displayed under image section.

PDO::FETCH_GROUP
[MySQL PDO Const]

PDO::FETCH_GROUP (integer)

Returns the results of calling the specified function, using each row's columns as parameters in the call.

Used with:

  • PDOStatement:: fetchAll  [more]

 

see also: PDO::FETCH_COLUMN

 

PDO::FETCH_COLUMN with grouping results by selected column (3rd from left). Grouping is done by PDO::FETCH_GROUP.

Items are groupped by status, which comes as: 0, 1, 2

code:

//FROM_UNIXTIME(:entry_date, '%Y-%m-%d %H:%i:%s') formats date properly - according to MySQL storage standard for datetime
//one could use php to format data: $entry_date = time("Y-m-d H:i:s", 1329109080);
$sql = "SELECT entry_title, entry_body, status FROM posts WHERE entry_date < FROM_UNIXTIME(:entry_date, '%Y-%m-%d %H:%i:%s') ";
$sth = $dbh->prepare($sql);

$entry_date = '1329109080';
$sth->bindParam(':entry_date', $entry_date, PDO::PARAM_STR);
$sth->execute();
$sth->bindColumn('entry_title', $entry_title, PDO::PARAM_STR);
$result = $sth->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP,2);

print_r($result);
var_dump($result);

output:

print_r:

Array
(
    [0] => Array
        (
            [0] => post 1
            [1] => post 2
            [2] => post 3
        )
 
    [2] => Array
        (
            [0] => post 4
            [1] => post 5
            [2] => post 6
        )
 
    [1] => Array
        (
            [0] => post 7
            [1] => post 8
            [2] => post 9
        )
)

var_dump:

array
  0 => 
    array
      0 => string 'post 1' (length=6)
      1 => string 'post 2' (length=6)
      2 => string 'post 3' (length=6)
  2 => 
    array
      0 => string 'post 4' (length=6)
      1 => string 'post 5' (length=6)
      2 => string 'post 6' (length=6)
  1 => 
    array
      0 => string 'post 7' (length=6)
      1 => string 'post 8' (length=6)
      2 => string 'post 9' (length=6)