Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f79f82

Browse files
committed
add fetch group support
1 parent 1a70c10 commit 9f79f82

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

mysql_prepare.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function mysql_execute(array $input_parameters = array(), $stmt, $link = null)
6969
*
7070
* @return mixed
7171
*/
72-
function mysql_fetch_all($result, $type = 'array')
72+
function mysql_fetch_all($result, $type = 'array', $group = false)
7373
{
7474
if($result === false)
7575
{
@@ -82,7 +82,29 @@ function mysql_fetch_all($result, $type = 'array')
8282
{
8383
if($row !== false)
8484
{
85-
$rows[] = $row;
85+
if(true === $group)
86+
{
87+
if($type === 'array')
88+
{
89+
array_shift($row);
90+
}
91+
92+
if($type === 'object')
93+
{
94+
$cols = get_object_vars($row);
95+
$col = array_shift($cols);
96+
}
97+
else
98+
{
99+
$col = array_shift($row);
100+
}
101+
102+
$rows[$col][] = $row;
103+
}
104+
else
105+
{
106+
$rows[] = $row;
107+
}
86108
}
87109
else
88110
{

0 commit comments

Comments
 (0)