Invert Axis

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alvinho
Forum Newbie
Posts: 1
Joined: Mon Aug 11, 2008 1:58 pm

Invert Axis

Post by alvinho »

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.

Example:
Image



I would like to swap the axis on this report.


Image



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








CODE

Code: Select all

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;
    
 
Post Reply