excel from php and MxSql

Topics: User Forum
Nov 26, 2011 at 12:18 PM

Hi

I have all the datas in a database and I would like to know if and how I can use PHPExcel? I only should put the data in a row. In normal PHP the code is as follow.

 

Tanks for yout tipps and helping

Graciela

 

<?php

$query="select `a`, `b`, `c`, `d` FROM db where deaktiviert ='' order by a";
$result=mysql_query($query,$link);?>

<table width=\"100%\" cellpadding=\"1\" cellspacing=\"1\" border=\"1\">
  <tr>
    <td><strong>A</strong></td>
    <td><strong>B</strong></td>
    <td><strong>C</strong></td>
    <td><strong>D</strong></td>
     </tr>
  <?php
 while($row = mysql_fetch_assoc($result))
  { ?>
  <tr>
    <td><?php if(!empty($row['a'])){echo"$row[a]";}else{ echo"&nbsp;";}?></td>
    <td><?php if(!empty($row['b'])){echo"$row[b]";}else{ echo"&nbsp;";}?></td>
    <td><?php if(!empty($row['c'])){echo"$row[c]";}else{ echo"&nbsp;";}?></td>
    <td><?php if(!empty($row['d'])){echo"$row[d]";}else{ echo"&nbsp;";}?></td>
  </tr>
    <?php } ?>
</table>

Nov 28, 2011 at 1:31 PM

Look at the samples in the Tests folder, like 01simple.php.

In your while loop, you would basically setCellValue() in place of echoing to table cells.

Dec 6, 2011 at 8:47 AM

Thanks

That works fine

while($row = mysql_fetch_row($result))
{
    $col = 'A';
    foreach($row as $cell) {
       
       $objPHPExcel->setActiveSheetIndex(0)->setCellValue($col.$rowNumber,$cell);
       $col++;
    }
    $rowNumber++;
}