Jump to content
Pardon our ads (a necessary update) ×

Swaping the Axis


alvinho

Recommended Posts

Hello everyone,

 

I need help with the following issue. I hope one of you could help me with it.

 

 

The code bellow will output the following report in html  and excel format.

 

Example:

exA.jpg

 

 

 

I would like to swap the axis like  in this report.

 

 

exB.jpg

 

 

 

I don't have a lot of experience with php/mysql, so I am having a hard time figuring this out.

Any feedbacks are welcome!

Thank you very much!

Alvinho

 

 

 

 


if(isset($_GET['export']) && ($_GET['export']==2)){
$link_id = AbreBD();
     $SQL2 = 'SELECT DISTINCT  D.CompanyName FROM tblDistributorsProducts DP INNER JOIN tblDistributors D ON DP.DistID = D.ID INNER JOIN tblProducts Pr ON DP.ProdID = Pr.ID WHERE '. $Cond .' AND D.isActive = 0 AND Pr.isActive = 0 ORDER BY D.CompanyName';      
     $SQL = 'SELECT DP.Price, Pr.Product, D.CompanyName FROM tblDistributorsProducts DP INNER JOIN tblDistributors D ON DP.DistID = D.ID INNER JOIN tblProducts Pr ON DP.ProdID = Pr.ID WHERE '. $Cond .' AND D.isActive = 0 AND Pr.isActive = 0 ORDER BY Pr.Product ASC, D.CompanyName ASC';
     $result2 = mysql_query($SQL2) or die(mysql_error());
    
     $result = mysql_query($SQL) or die(mysql_error());
     $output = '<table id="tab">';
     $output.="<tr><td>Product / Distributor</td>";
     $i = 1;
     while($col = mysql_fetch_array($result2)){
         $output.='<td id="comp'.$i.'"><b>'.$col['CompanyName'].'</b></td>';
     }
  
     while($row = mysql_fetch_array($result)){
         if($prod!=$row['Product']){
             $output.="</tr><tr><td>$row[Product]</td>";
             $prod = $row['Product'];$i=1;
         }
        
         $ok=0;
        
         while($ok!=1){
         $result3 = mysql_query($SQL2) or die(mysql_error());
             for( $k=0; $k<$i; $k++ ){
                 $comp = mysql_fetch_array($result3);
             }
             if($row['CompanyName'] == $comp['CompanyName']){
                 $output.="<td>$row[Price]</td>";
                 $ok=1;
             }
             else{
                 $output.="<td></td>";
             }
             $i++;
         }   
     }
     $output.="</tr>";  
     $output.="</table>";
     FechaBD($link_id);
     header("Content-type:application/vnd.ms-excel");
     header("Content-disposition:attachment;filename=ProductList.xls");     
     print $output;

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/119214-swaping-the-axis/
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.