alvinho Posted August 11, 2008 Share Posted August 11, 2008 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: I would like to swap the axis like in this report. 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 More sharing options...
discomatt Posted August 11, 2008 Share Posted August 11, 2008 I'd suggest the freelance forum for this one. Link to comment https://forums.phpfreaks.com/topic/119214-swaping-the-axis/#findComment-614046 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.