简体   繁体   中英

Group the output of PDO query

I have a PDO query in which I am doing inner join on two tables and extracting the columns required by me. Now these two columns are - status, script. Status can be - passed, failed, incomplete and

script - scripts/testSuite/layer3Features/ManualStaticRouting/manualStaticRoutes.tcl , scripts/testSuite/hostAgentFeatures/dhcp/DHCP IPv6/RelayBBasicFunc/ipv6DhcpRelayEnableDhcpv6RelayGlobally.tcl

the output of --

while($row = $getFamily->fetch(PDO::FETCH_ASSOC))
        { 
        foreach($row as $key) 
            {
                print_r($row);
}

is -

http://pastebin.com/WqcibEyp

the full query is -

$testType = 'TCL';

    $getFamily = $conn->prepare('SELECT testcases2.script, results3.status FROM testcases2 INNER JOIN results3 ON testcases2.testcaseID = results3.testcaseID
    WHERE testType = :testType');

    $getFamily->execute(array(':testType' => $testType));

      while($row = $getFamily->fetch(PDO::FETCH_ASSOC))
        { 
        foreach($row as $key) 
            {
                print_r($row);
                $family[] = $key;
            }           
        }

Now here what I want to do is, read the second location of each script (considering scripts at 0) and group all the values which have same stuff in the third location, with status together.

How this can be done. Please guide.

You need to group your script and status like this,

while($row = $getFamily->fetch(PDO::FETCH_ASSOC))
{ 
   $status[] = $row['status'];
   $scripts[] = $row['script'];
}

print_r($scripts);
print_r($status);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM