Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Valabilitate permis auto cat. A s...

Caramida aparenta peste termosistem

Linistea din timpul penelor de cu...

Achiziție laptop baterie det...
 Cenzura in masa comentarii youtube

Inscriere copil la scoala in Roma...

exista adaptoare pentru baterii P...

Sa folosim antivirus, antimalware?
 SMS suspect livrare "posta ro...

Film original sau pirat?

Cum poti inregistra CD-uri in for...

Ceainaria celor pasionați de...
 Probleme la acoperis din cauza in...

Transferuri instant intre bancile...

player video cu preview cadru pe ...

Carrefour Act for good
 

Nu pot exporta in Excel

- - - - -
  • Please log in to reply
1 reply to this topic

#1
geotux

geotux

    Junior Member

  • Grup: Junior Members
  • Posts: 49
  • Înscris: 12.07.2019
Salut !

Vreau sa export datele dintr-un tabel creat cu DataTables, dar nu exporta decat header-ul tabelului.
Poate cineva are experienta cu DataTables.

<script>
$(document).ready( function () {
let table = new DataTable('#example', {
	 dom: 'Bfrtip',
	 buttons: [
		 'excel' , 'csv'
	 ]
});

} );
</script>
<div class="row">
		 <!-- name -->
		 <div class="col-xl-2 col-lg-7">
			 <div class="card shadow mb-4" id="sp_nume">
			 <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between" >
				 <h6 class="m-0 font-weight-bold text-primary">Scientific Name: </h6><span id="myoption"></span>
				 </div>
				 <?php
				 $link = mysqli_connect("localhost", "root", "", "regime_shift");
				 // Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
				 $sql1 = "SELECT DISTINCT `ScientificName_accepted` FROM `all_20082018` WHERE 1";
			 $result = mysqli_query($link,$sql1);
			 ?>
<div class="form-group">
<select class="form-control dropdown" id="specie" onchange="selectSpecie()">
	 <option disabled value="">Selecteaza o specie</option>
	 <?php while ($row = mysqli_fetch_array($result)) {
						 echo "<option value='" . $row['ScientificName_accepted'] ."' >" . $row['ScientificName_accepted'] ."</option>";
			 }
			 ?>

</select>
</div>
</div>
			 </div>
			 <!-- statia -->
			 <div class="col-xl-2 col-lg-7">
			 <div class="card shadow mb-4" id="sp_nume">
			 <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between" >
				 <h6 class="m-0 font-weight-bold text-primary">Statia: </h6><span id="myoption"></span>
				 </div>
				 <?php

				 $sql2 = "SELECT DISTINCT `Statia` FROM `all_20082018` WHERE 1";
			 $result = mysqli_query($link,$sql2);
			 ?>
<div class="form-group">
<select class="form-control dropdown" id="statia" onchange="selectSpecie()">
	 <option disabled value="">Selecteaza o statie</option>
	 <?php while ($row = mysqli_fetch_array($result)) {
						 echo "<option value='" . $row['Statia'] ."' >" . $row['Statia'] ."</option>";
			 }
			 ?>

</select>
</div>
</div>
			 </div>
		 </div>
<table id="example" class="display nowrap" style="width:100%">
			 <thead>
				 <tr>
				 <th>Month</th>
				 <th>Year</th>
				 <th>Class</th>
				 <th>Order</th>
				 <th>Biomasa</th>
				 <th>Statia</th>
				 </tr>
			 </thead>
			 <tbody id="ans">
			 </tbody>
		 </table>


Tabelul este populat cu data dinamic cu ajax, in functie de ce selecteaza userul in cele doua campuri select:

function selectSpecie() {
var x1 = document.getElementById("specie").value;
var x2 = document.getElementById("statia").value;
$.ajax({
	 url:"showResults.php",
	 method: "POST",
	 data:{id1 : x1,id2 : x2},
	 success:function(data){
		 $("#ans").html(data);
	 }
})
}


si api-ul :
<?php
$k1 = $_POST['id1'];
$k1 = trim($k1);
$k2 = $_POST['id2'];
$k2 = trim($k2);
$link = mysqli_connect("localhost", "root", "", "regime_shift");
								 // Check connection
if($link === false){
	 die("ERROR: Could not connect. " . mysqli_connect_error());
}

$sql1 = "SELECT * FROM `all_20082018` WHERE ScientificName_accepted='{$k1}' AND Statia='{$k2}'";
$result = mysqli_query($link,$sql1);
while($rows=mysqli_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['Month'] ;?></td>
<td><?php echo $rows['Year'] ;?></td>
<td><?php echo $rows['Class'] ;?></td>
<td><?php echo $rows['Order'] ;?></td>
<td><?php echo $rows['BIOMASA'] ;?></td>
<td><?php echo $rows['Statia'] ;?></td>
</tr>
<?php
}
echo $sql1;
?>



#2
geotux

geotux

    Junior Member

  • Grup: Junior Members
  • Posts: 49
  • Înscris: 12.07.2019
Ok...am renuntat la ajax...fac interogarea direct in pagina... si acum merge ok, pot exporta in excel

Deci, consider rezolvata problema

Numai bine ! Posted Image

Anunturi

Bun venit pe Forumul Softpedia!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate