0

I tried different solutions to extract data from table to xls, jquery standart methonds, plugins etc. But it does not work. I think the problem is in table structure. All plugins extract data from clean HTML tables, but my table gets data from php, so maybe this is the reason of the problem? How can I extract data to xls from this table:

<table cellspacing="1" id="table-exp" class="tablesorter">
        <thead>
            <tr> 
                <th>Маршрут</th> 
                <th>Идентификатор</th>
                <th>Дата</th> 
                <th>Время в минутах</th> 
                <th>Время в секундах</th> 
                <th>Средняя скорость</th> 
                <th>Расстояние</th>
                <th>Стоимость топлива</th> 
            </tr> 
        </thead>        
    <?php
        $result = mysql_query("SELECT * FROM trackdata ORDER BY `dateC` DESC");
        if (!$result) {
            echo 'Could not run query: ' . mysql_error();
            exit;
        }
        echo "<tbody>";
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
        echo "<tr>";
        echo "<td>",$row["trackID"],"</td>";
        echo "<td>",$row["uuid"],"</td>";
        echo "<td>",$row["dateC"],"</td>";
        echo "<td>",$row["timeInMinutes"],"</td>";
        echo "<td>",$row["timeInSeconds"],"</td>";
        echo "<td>",$row["averageSpeed"],"</td>";
        echo "<td>",$row["distance"],"</td>";
        echo "<td>",round($row["distance"] * 1.2, 2)," грн</td>";
        echo "</tr>";
        }
        echo "</tbody>";
        mysql_free_result($result);

    ?>
        <tfoot>
            <tr> 
                <th>Маршрут</th> 
                <th>Идентификатор</th>
                <th>Дата</th> 
                <th>Время в минутах</th> 
                <th>Время в секундах</th> 
                <th>Средняя скорость</th> 
                <th>Расстояние</th> 
                <th>Стоимость топлива</th> 
            </tr> 
        </tfoot> 
    </table>

I think jquery plugins cannot parse such table because of php code part. How to deal with it? How to extract data in this case?

user3166813
  • 99
  • 1
  • 1
  • 10
  • So why not do your xls exporter in PHP as well, there's plenty of examples and libraries to help with that.... but jquery isn't even aware of the existence of PHP code, it can't see it, so jquery doesn't know that your table was generated by PHP or not.... it can only see the html that has been rendered – Mark Baker Jun 01 '14 at 12:34
  • If jquery plugins will only work with "clean" html tables, then you make sure that the html table generated by your PHP code is "clean" – Mark Baker Jun 01 '14 at 12:37
  • Thanks for answer. My table is not generated by PHP, it`s clean HTML, but data in this table is generated by PHP – user3166813 Jun 01 '14 at 13:01
  • Then I fail to understand the problem: if the plugins only work with "clean" html, and your html is "clean", then what is the issue? PHP Is irrelevant, it only generates the html, and jquery (as I said) doesn't know or care how the html was generated – Mark Baker Jun 01 '14 at 13:18
  • I will try some PHP solution to extract data. Thanks – user3166813 Jun 01 '14 at 15:24
  • While I still can't understand what your problem is with jquery plug-ins, there's dozens of PHP libraries for generating xls files, in addition to my own [PHPExcel](https://github.com/PHPOffice/PHPExcel) library, there's a list [here](http://stackoverflow.com/questions/3930975/alternative-for-php-excel/3931142#3931142) – Mark Baker Jun 01 '14 at 15:31

0 Answers0