making pivot style table in php

abhijeet2021

Broken In
Hi

am new in php and am developing an interface for our team.
now here is some bottleneck i need to eliminate. Following is my code example

Code:
$results1=pg_query("select rpc.productkey, rpc.actiontype, rpc.rate from mytable1 rpc, mytable2 r where rpc.resellerid=r.resellerid and rpc.resellerid in (".$txtrid.") order by resellerid, productkey, actiontype");

print "<p><b>Reseller Pricing Details:</b><p>";   
print "<p><table border='1' cellpadding='1' cellspacing='1'><tr>";
print "<th>Product Key</th>";
print "<th>Action Type</th>";
print "<th>Pricing</th></tr>";

while($db_fields1=pg_fetch_assoc($results1))
{
print "<tr><td>".$db_fields1['productkey']."</td>";
print "<td>".$db_fields1['actiontype']."</td>";
print "<td>".$db_fields1['rate']."</td></tr>";
}
print "</table";
pg_close($pg_handle);

output i get is like this

Product Key | Action Type |
dombiz | addnewdomain |
dombiz | addtransferdomain |
dombiz | renewdomain |
dombiz | restoredomain |
domcno | addnewdomain |
domcno | addtransferdomain |
domcno | renewdomain |
domcno | restoredomain |
dominfo | addnewdomain |
dominfo | addtransferdomain |
dominfo | renewdomain |
dominfo | restoredomain |
domorg | addnewdomain |
domorg | addtransferdomain |
domorg | renewdomain |
domorg | restoredomain |
domus | addnewdomain |
dotco | addnewdomain |
dotco | addtransferdomain |
dotco | renewdomain |
dotin | addnewdomain |
dotin | addtransferdomain |
dotin | renewdomain |
dotin | restoredomain |
dotme | addnewdomain |
dotmobi | addnewdomain |
dotmobi | addtransferdomain |
dotmobi | renewdomain |
dotnet | addnewdomain |
dotnet | addtransferdomain |
dotnet | renewdomain |
dotnet | restoredomain |
thirdleveldotco | addnewdomain |
thirdleveldotco | addtransferdomain |
thirdleveldotco | renewdomain |
thirdleveldotin | addnewdomain |
thirdleveldotin | addtransferdomain |
thirdleveldotin | renewdomain |
thirdleveldotin | restoredomain |

now i want a pivot like output similar to like this

| addnewdomain | addtransferdomain | renewdomain | restoredomain
dombiz | 0.35 | 0.35 | 0.35 | 5
domcno | 0.35 | 0.35 | 0.35 | 5
dominfo | 0.35 | 0.35 | 0.35 | 5
domorg | 0.35 | 0.35 | 0.35 | 5
domus | 6.39 | | |
dotco | 23.5 | 23.5 | 23.5 |
dotin | 0.2 | 0.2 | 0.2 | 5
dotme | 20 | | |
dotmobi | 13.49 | 13.49 | 13.49 |
dotnet | 0.35 | 0.35 | 0.35 | 5
thirdleveldotco | 11.99 | 11.99 | 11.99 |
thirdleveldotin | 0.2 | 0.2 | 0.2 | 5

dunno how to do about it as i am new to php. kindly help me on this
 
Last edited:
Top Bottom