Za pomocą poniższego kodu chciałem zapisać do pliku xls wybrane pozycje z wyniku zapytania do bazy (poprzez checkboxy), niestety po zainicjowaniu akcji nie kreuje się xls ...
widzę tylko w 'developer tools' chrome ze dane przez 'post' są przekazywane do porządanej podstrony (export.php) ale nic pozatym się nie dzieje.
Prosze o jakieś wskazówki gdzie może być błąd.
ponizej kod:
baza.php:
<!DOCTYPE html> <html lang="pl"> <head> ... <script type="text/javascript"> $(function(){ $("#myTable").tablesorter(); }); </script> <script type="text/javascript"> $(function(){ $("#myTable").tablesorter({ sortList: [[0,0], [1,0]] }); }); </script> </head> <body style="margin: 0; padding: 0"> <div class="wrapper"> <div class="baza"> </div> <div class="search"> <form action="baza_site.php" method="POST"> <div class="input-group"> <input type="text" class="form-control" placeholder="Search" name="search"> <div class="input-group-btn"> <button class="btn btn-default" type="submit" name="submit" > </button> </div> </div> </form> </div> <div class="tabela"> // Include config file require_once 'config.php'; if (isset($_POST["submit"])) { $search = mysqli_real_escape_string($mysqli, trim($_POST['search'])); mysqli_set_charset( $mysqli, 'utf8'); $sql = "SELECT * FROM baza_site WHERE site LIKE '%$search%' OR city LIKE '%$search%' OR address LIKE '%$search%' OR accessDetails LIKE '%$search%' OR ServiceArea LIKE '%$search%' OR locationType LIKE '%$search%'"; if($result = $mysqli->query($sql)){ if($result->num_rows > 0){ $ilosc = mysqli_num_rows($result); echo "<table id='myTable' class='tablesorter-blackice'>"; echo "<thead>"; echo "<tr>"; echo "</tr>"; echo "</thead>"; echo "<tbody>"; while($row = $result->fetch_array()){ echo "<tr>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; // Free result set $result->free(); } else{ } } else{ echo "ERROR: Could not able to execute $sql. " . $mysqli->error; } } // Close connection $mysqli->close(); ?> </div> </div> <script type="text/javascript"> $("#myTable").tablesorter({ headers: { 0: { sorter: false, parser: false } } }); <script type="text/javascript"> $('#checkall').change(function(){ $('.checkitem').prop("checked", $(this).prop("checked")) }) $('#export').click(function(){ var id = $('.checkitem:checked').map(function(){ return $(this).val() }).get().join(' ') $.post('export.php?p=xls', {id : id}) }); </script> </body> </html>
export.php:
<?php require_once 'config.php'; $id=''; $output = ''; if($page == 'xls'){ $myid = $_POST['id']; $sql = "SELECT * FROM baza_site WHERE id IN($id)"; if($result = $mysqli->query($sql)){ if($result->num_rows > 0) { $output .= ' <table border="1"> <tr> <th>id</th> <th>site</th> <th>location type</th> <th>city</th> <th>address</th> <th>access details</th> <th>service area</th> </tr> '; while($row = mysqli_fetch_array($result)) { $output .= ' <tr> <td>'.$row["id"].'</td> <td>'.$row["site"].'</td> <td>'.$row["locationType"].'</td> <td>'.$row["city"].'</td> <td>'.$row["address"].'</td> <td>'.$row["accessDetails"].'</td> <td>'.$row["ServiceArea"].'</td> </tr> '; } $output .= '</table>'; } }} $mysqli->close(); ?>