Method pot-php, mysqli and fpdf - php

I have tried to make a report using FPDF.
While sending the form data to the Query in FPDF, does not show me the data
Form
include_once('PDF.php');
require 'conexion.php';
$where = "";
if (isset($_POST['buscar'])) {
$desde = date('Y-m-d',strtotime ($_POST['desde']));
//$hasta = date('Y-m-d', strtotime($_POST['hasta']));
$valor = $_POST['campo'];
if (empty($_POST['dese'])) {
$where = "WHERE proveedores LIKE '%".$valor."%' ORDER BY cxl ASC";
} elseif (empty($POST['campo'])) {
$where = "WHERE f_elaboracion = '".$desde."' ORDER BY cxl ASC";
}else{
$where = "WHERE proveedores LIKE '".$valor."' AND f_elaboracion = '".$desde."' ORDER BY cxl ASC";
}
}
$sql = "SELECT * FROM retensiones $where";
$resultado = $mysqli->query($sql);?>
<html lang="es">
<body>
<div class="container">
<div class="row">
<h2 style="text-align:center">FORMULARIO</h2>
</div>
<div class="row">
<form method="POST" >
<select name="campo">
<option value="2">Proveedor</option>
<?php
$query = $mysqli -> query ("SELECT proveedores FROM proveedores ORDER BY proveedores ASC");
while ($valores = mysqli_fetch_array($query)) {
echo '<option value="'.$valores[proveedores].'">'.$valores[proveedores].'</option>';
}?>
</select>
<td>Desde : </td>
<td><input type="date" id="desde" name="desde"/></td>
<button name="buscar" type="submit" class="btn btn-info" >Buscar</button>
<td width="200"><a target="_blank" href="indexpdf.php" class="btn btn-danger">Exportar Busqueda a PDF</a></td>
</form>
</div>
<div class="row table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>CXL</th>
<th>FECHA</th>
<th>Concepto</th>
<th>Periodo</th>
<th>Importe</th>
<th>I.V.A.</th>
<th>I.S.R.</th>
</tr>
</thead>
<tbody>
<?php while($row = $resultado->fetch_array(MYSQLI_ASSOC))
{?>
<tr>
<td><?php echo $row['cxl']; ?></td>
<td><?php echo date('d/m/Y',strtotime($row['f_elaboracion'])); ?></td>
<td><?php echo $row['concepto']; ?></td>
<td><?php echo $row['periodo']; ?></td>
<td><?php echo number_format (($row['importe']),'2','.',','); ?></td>
<td><?php echo number_format (($row['iva']),'2','.',','); ?></td>
<td><?php echo number_format (($row['isr']),'2','.',','); ?></td>
</tr>
<?php
}?>
</tbody>
</table>
</div>
</div>
</body>
</html>
FPDF TEMPLATE
$mysqli = new mysqli('localhost', 'root', 'pasword.123', 'tesoreria');
if($mysqli->connect_error){
die('Error en la conexion' . $mysqli->connect_error);
}
$where = "";
if(isset($_POST['buscar'])) {
$desde = date('Y-m-d',strtotime ($_POST['desde']));
//$hasta = date('Y-m-d', strtotime($_POST['hasta']));
$valor = $_POST['campo'];
if (empty($_POST['dese'])) {
$where = "WHERE proveedores LIKE '%".$valor."%' ORDER BY cxl ASC";
} else if (empty($POST['campo'])){
$where = "WHERE f_elaboracion = '".$desde."' ORDER BY cxl ASC";
} else {
$where = "WHERE proveedores LIKE '".$valor."' AND f_elaboracion = '".$desde."' ORDER BY cxl ASC";
}
}
$sql = "SELECT * FROM retensiones $where";
$result = $mysqli->query($sql);
include_once('PDF.php');
$pdf = new PDF();
$pdf->AliasNbPages();//Genera el numero de paginas finales
$pdf->AddPage();//Agrega una nueva pagina
$rows=0; // inicia el contador de fila
$totalimporte=0;
$totaliva=0;
$totalisr=0;
$pdf->SetXY(10,80);
$pdf->SetFont('Arial','',10);
$pdf->SetTextColor(3,3,3);//Coor del Texto Negro
while ($fila = $result->fetch_assoc())
{
$pdf->Cell(20,7, utf8_decode($fila['cxl']),0,0,'L');
$pdf->Cell(25,7, date('d/m/Y',strtotime($fila['f_elaboracion'])),0,0,'L'); //date strtotime , da el formato dia mes año
$pdf->Cell(45,7, utf8_decode($fila['concepto']),0,0,'L');
$pdf->Cell(25,7, utf8_decode($fila['periodo']),0,0,'L');
$pdf->Cell(25,7, number_format (($fila['importe']),'2','.',',') ,0,0,'L'); // numer format , le da el formato en centenas miles y millones
$pdf->Cell(25,7, number_format (($fila['iva']),'2','.',','),0,0,'L');
$pdf->Cell(25,7, number_format (($fila['isr']),'2','.',','),0,0,'L');
$pdf->Ln();
$rows++; //suma 1 al contador
$totalimporte= $totalimporte + ($fila['importe']);
$totaliva = $totaliva + ($fila['iva']);
$totalisr = $totalisr + ($fila['isr']);
if($rows==22) { // si el numero de fila es igual a 20
$rows = 0; //vuelve el contador cero y
$pdf->AddPage(); // agrega una nueva pagina
}
}
$pdf->Ln();
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('Arial','B',10);
$pdf->Cell(20,7 ,"TOTALES",1,0,'L');
$pdf->SetX(115);
$pdf->SetFont('Arial','',12);
$pdf->Cell(30,10, number_format (($totalimporte),'2','.',',') ,1,0,'L');
$pdf->Cell(30,10, number_format (($totaliva),'2','.',',') ,1,0,'L');
$pdf->Cell(30,10, number_format (($totalisr),'2','.',',') ,1,0,'L');
$pdf->Output();//Salida del navegador
mysql_close($conexion);

Your <a target="_blank" href="indexpdf.php" class="btn btn-danger">Exportar Busqueda a PDF</a> does not send the form data. You can use Jquery to send the data you want to the PDF template.
include_once('PDF.php');
require 'conexion.php';
$where = "";
if (isset($_POST['buscar'])) {
$desde = date('Y-m-d',strtotime ($_POST['desde']));
//$hasta = date('Y-m-d', strtotime($_POST['hasta']));
$valor = $_POST['campo'];
if (empty($_POST['dese'])) {
$where = "WHERE proveedores LIKE '%".$valor."%' ORDER BY cxl ASC";
} elseif (empty($POST['campo'])) {
$where = "WHERE f_elaboracion = '".$desde."' ORDER BY cxl ASC";
}else{
$where = "WHERE proveedores LIKE '".$valor."' AND f_elaboracion = '".$desde."' ORDER BY cxl ASC";
}
}
$sql = "SELECT * FROM retensiones $where";
$resultado = $mysqli->query($sql);?>
<html lang="es">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<Script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<Script type="text/javascript">
$(document).ready(function () {
$("#indexPDF").click(function(){
submit('indexpdf.php', 'POST', [
{ name: 'desde', value: $('#desde').val() },
{ name: 'campo', value: $('#campo').val() }
], '_blank');
});
});
function submit(action, method, values, target) {
var form = $('<form/>', {
action: action,
method: method,
target: target
});
$.each(values, function() {
form.append($('<input/>', {
type: 'hidden',
name: this.name,
value: this.value
}));
});
form.appendTo('body').submit();
}
</SCRIPT>
</head>
<body>
<div class="container">
<div class="row">
<h2 style="text-align:center">FORMULARIO</h2>
</div>
<div class="row">
<form method="POST" >
<select name="campo">
<option value="2">Proveedor</option>
<?php
$query = $mysqli -> query ("SELECT proveedores FROM proveedores ORDER BY proveedores ASC");
while ($valores = mysqli_fetch_array($query)) {
echo '<option value="'.$valores[proveedores].'">'.$valores[proveedores].'</option>';
}?>
</select>
<td>Desde : </td>
<td><input type="date" id="desde" name="desde"/></td>
<button name="buscar" type="submit" class="btn btn-info" >Buscar</button>
<td width="200"><div id="indexPDF" class="btn btn-danger">Exportar Busqueda a PDF</div></td>
</form>
</div>
<div class="row table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>CXL</th>
<th>FECHA</th>
<th>Concepto</th>
<th>Periodo</th>
<th>Importe</th>
<th>I.V.A.</th>
<th>I.S.R.</th>
</tr>
</thead>
<tbody>
<?php while($row = $resultado->fetch_array(MYSQLI_ASSOC))
{?>
<tr>
<td><?php echo $row['cxl']; ?></td>
<td><?php echo date('d/m/Y',strtotime($row['f_elaboracion'])); ?></td>
<td><?php echo $row['concepto']; ?></td>
<td><?php echo $row['periodo']; ?></td>
<td><?php echo number_format (($row['importe']),'2','.',','); ?></td>
<td><?php echo number_format (($row['iva']),'2','.',','); ?></td>
<td><?php echo number_format (($row['isr']),'2','.',','); ?></td>
</tr>
<?php
}?>
</tbody>
</table>
</div>
</div>
</body>
</html>
I changed your code
<a target="_blank" href="indexpdf.php" class="btn btn-danger">Exportar Busqueda a PDF</a>
to
<div id="indexPDF" class="btn btn-danger">Exportar Busqueda a PDF</div>
Missing is the Style sheet. I edited the above code to include the style sheet.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

Related

Load more button value according "WHERE" Clouse condition

I am using load more button to load content from the database of specific id on the same web page. Here is the code:
<div class="postList col-lg-12">
<legend><h1 style="color:#298208;">Savings Bucks Details</h1> </legend>
<?php
$busi_id = mysqli_real_escape_string($conn, $_SESSION['busi_id']);
if (isset($busi_id)) {
$query = "SELECT * FROM savingsbucks_business WHERE busi_id='$busi_id' ORDER BY sbb_id DESC LIMIT 2";
$result = mysqli_query($conn, $query) or die('Query failed: ' . mysqli_error($conn));
$numrows_savingsbucks = mysqli_num_rows($result);
if ($numrows_savingsbucks == '0') {
echo "<p style='text-align:center; color:#ff4400; margin-top:40px;'>No Data available!</p>";
} else {
?>
<div class="table-responsive">
<table border="1" class="table table-bordered">
<thead>
<th class="consumer_point_text">Shop ID</th>
<th class="consumer_point_text">SenderID</th>
<th class="consumer_point_text">Busi ID</th>
<th class="consumer_point_text">Customer Type</th>
<th class="consumer_point_text">Customer Name</th>
<th class="consumer_point_text">Customer Email</th>
<th class="consumer_point_text">Customer Phone</th>
<th class="consumer_point_text">Two</th>
<th class="consumer_point_text">Five</th>
<th class="consumer_point_text">Ten</th>
<th class="consumer_point_text">Twenty</th>
<th class="consumer_point_text">Fifty</th>
<th class="consumer_point_text">Hundred</th>
<th class="consumer_point_text">Five Hundred</th>
<th class="consumer_point_text">Total Savings Bucks</th>
</thead>
<?php if($numrows_savingsbucks > 0){
while ($row = mysqli_fetch_array($result)) {
$sbb_id = $row['sbb_id'];
$sender_id = $row['sender_id'];
$busi_id = $row['busi_id'];
$type = $row['type'];
$consu_name = $row['consu_name'];
$consu_email = $row['consu_email'];
$consu_phone = $row['consu_phone'];
$two = $row['two'];
$five = $row['five'];
$ten = $row['ten'];
$twenty = $row['twenty'];
$fifty = $row['fifty'];
$hundred = $row['hundred'];
$five_hundred = $row['five_hundred'];
$total_two += $two;
$total_five += $five;
$total_ten += $ten;
$total_twenty += $twenty;
$total_fifty += $fifty;
$total_hundred += $hundred;
$total_five_hundred += $five_hundred;
$total_bucks = $two+$five+$ten+$twenty+$fifty+$hundred+$five_hundred;
$grand_total += $total_bucks;
?>
<tr>
<td class="consumer_point_text"><?=$sbb_id?></td>
<td class="consumer_point_text"><?=$sender_id?></td>
<td class="consumer_point_text"><?=$busi_id?></td>
<td class="consumer_point_text" style="text-transform:capitalize;"><?=$type?></td>
<td class="consumer_point_text"><?=$consu_name?></td>
<td class="consumer_point_text"><?=$consu_email?></td>
<td class="consumer_point_text"><?=$consu_phone?></td>
<td class="consumer_point_text"><?=$two?></td>
<td class="consumer_point_text"><?=$five?></td>
<td class="consumer_point_text"><?=$ten?></td>
<td class="consumer_point_text"><?=$twenty?></td>
<td class="consumer_point_text"><?=$fifty?></td>
<td class="consumer_point_text"><?=$hundred?></td>
<td class="consumer_point_text"><?=$five_hundred?></td>
<td class="consumer_point_text"><?=$total_bucks?></td>
</tr>
<?php } ?>
</table>
<div class="show_more_main" sbb_id="show_more_main<?php echo $sbb_id; ?>">
<span sbb_id="<?php echo $sbb_id; ?>" class="show_more" title="Load more posts">Load more</span>
<span class="loding" style="display: none;"><span class="loding_txt">Loading...</span></span>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script
<script src="http://demos.codexworld.com/includes/js/bootstrap.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click','.show_more',function(){
var ID = $(this).attr('sbb_id');
$('.show_more').hide();
$('.loding').show();
$.ajax({
type:'POST',
url:'ajax_more_business_shop.php',
data:'sbb_id='+ID,
success:function(html){
$('#show_more_main'+ID).remove();
$('.postList').append(html);
}
});
});
});
</script>
<?php } ?>
</div> <!-- ./col-lg-12 -->
<?php } }?>
On this page its displaying 2 results which have common busi_id (WHERE busi_id=$busi_id), when I click on load more button, its displaying others content too which don't have same "busi_id" as on this page showing first 2 results.
Here is ajax page:
ajax_more_business_shop.php :
<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
if(!empty($_POST["sbb_id"])) {
require_once ('admin/includes/config.php');
$query = "SELECT COUNT(*) as num_rows FROM savingsbucks_business WHERE sbb_id < ".$_POST['sbb_id']." ORDER BY sbb_id DESC";
$result = mysqli_query ($conn, $query);
$row = mysqli_fetch_assoc($result);
$totalRowCount = $row['num_rows'];
$busi_id = $row['busi_id'];
$showLimit = 2;
$query = "SELECT * FROM savingsbucks_business WHERE sbb_id < ".$_POST['sbb_id']." ORDER BY sbb_id DESC LIMIT $showLimit";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
$rowcount=mysqli_num_rows($result);
?>
<table border="1" class="table table-bordered">
<?php
if ($rowcount > '0') {
while($row = mysqli_fetch_assoc($result))
{
$sbb_id = $row['sbb_id'];
$sender_id = $row['sender_id'];
$busi_id = $row['busi_id'];
$type = $row['type'];
$consu_name = $row['consu_name'];
$consu_email = $row['consu_email'];
$consu_phone = $row['consu_phone'];
$two = $row['two'];
$five = $row['five'];
$ten = $row['ten'];
$twenty = $row['twenty'];
$fifty = $row['fifty'];
$hundred = $row['hundred'];
$five_hundred = $row['five_hundred'];
$total_two += $two;
$total_five += $five;
$total_ten += $ten;
$total_twenty += $twenty;
$total_fifty += $fifty;
$total_hundred += $hundred;
$total_five_hundred += $five_hundred;
$total_bucks = $two+$five+$ten+$twenty+$fifty+$hundred+$five_hundred;
$grand_total += $total_bucks;
?>
<tr>
<td class="consumer_point_text"><?=$sbb_id?></td>
<td class="consumer_point_text"><?=$sender_id?></td>
<td class="consumer_point_text"><?=$busi_id?></td>
<td class="consumer_point_text"><?=$type?></td>
<td class="consumer_point_text"><?=$consu_name?></td>
<td class="consumer_point_text"><?=$consu_email?></td>
<td class="consumer_point_text"><?=$consu_phone?></td>
<td class="consumer_point_text"><?=$two?></td>
<td class="consumer_point_text"><?=$five?></td>
<td class="consumer_point_text"><?=$ten?></td>
<td class="consumer_point_text"><?=$twenty?></td>
<td class="consumer_point_text"><?=$fifty?></td>
<td class="consumer_point_text"><?=$hundred?></td>
<td class="consumer_point_text"><?=$five_hundred?></td>
<td class="consumer_point_text"><?=$total_bucks?></td>
</tr>
<?php }
?>
</table>
<?php if($totalRowCount > $showLimit){ ?>
<div class="show_more_main" sbb_id="show_more_main<?php echo $sbb_id; ?>">
<span sbb_id="<?php echo $sbb_id; ?>" class="show_more" title="Load more posts">Show more</span>
<span class="loding" style="display: none;"><span class="loding_txt">Loading...</span></span>
</div>
<?php } ?>
<?php
}
}
?>
I want, when i click "load more button", It must show/load 2 more row of content where busi_id will be common, I mean if busi_id=69, it should show/load only 2 more content/result from database which have busi_id 69, not other data with different busi_id.
I tried to explain,
Thank you.
I have just passed the "busi_id" to Ajax page... with load more button..
<div class="show_more_main" ds_id="show_more_main<?php echo $ds_id; ?>">
<span ds_id="<?php echo $ds_id; ?>" busi_id="<?php echo $busi_id; ?>" class="show_more" title="Load more posts">Load more</span>
<span class="" style="display: none;"><span class="loding_txt">Loading...</span></span>
</div>
And..
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click','.show_more',function(){
var ID = $(this).attr('ds_id');
var Busi_id = $(this).attr('busi_id');
$('.show_more').hide();
$('.loding').show();
$.ajax({
type:'POST',
url:'ajax_more_consumer_shop.php',
data: {
'ds_id': ID,
'busi_id': Busi_id
},
success:function(html){
$('#show_more_main'+ID).remove();
$('.postList').append(html);
}
});
});
});
on ajax_more_business_shop.php....
$query = "SELECT COUNT(*) as num_rows FROM savingsbucks_business WHERE ds_id < ".$_POST['ds_id']." AND busi_id=".$_POST["busi_id"]." ORDER BY ds_id DESC";
$result = mysqli_query ($conn, $query);
$row = mysqli_fetch_assoc($result);
$totalRowCount = $row['num_rows'];
$showLimit = 2;
$query = "SELECT * FROM savingsbucks_business WHERE ds_id < ".$_POST['ds_id']." AND busi_id=".$_POST["busi_id"]." ORDER BY ds_id DESC LIMIT $showLimit";
$result = mysqli_query ($conn, $query);
$rowcount=mysqli_num_rows($result);
Modified the query.. and get the desired output.
Thanks!

How to export this table of data to Excel file from php

can anyone here help with the code to export to an Excel file i hope that someone can because I already have an export button.
I want to keep the most with this code because this code works well. and if you want to see the export.php ask for it.
here a picture
enter image description here
<a class="btn btnx btn-orange" href="export.php" target="_new"><i class="fa fa-download"></i> Export to Excel</a>
<div class="table-responsive">
<table id="mytable" class="table table-bordred table-striped">
<thead>
<tr>
<th>#</th>
<th>Auditeur</th>
<th>Afdeling</th>
<th>Invoerdatum</th>
<th>Week</th>
<th>Zone</th>
<th>Stand</th>
<th>Zijn alle overbodeige gereedschappen / materialen van de werkpost verwijderd / geïdentificeerd? ( sleutel, bouten / moeren,.... )</th>
<th>Opgeslagen foto nr1</th>
<th>Is er rommel aanwezig op de werkpost ( bekertjes, kledij, flesjes,....)</th>
<th>Opgeslagen foto nr2</th>
<th>Zijn vervallen / niet geautoriseerde documenten verwijderd?</th>
<th>Opgeslagen foto nr3</th>
<th>Opmerking</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$fetchdata=new DB_con();
$sql=$fetchdata->fetchdata();
$cnt=1;
while($row=mysqli_fetch_array($sql))
{
?>
<tr>
<td><?php echo htmlentities($cnt);?></td>
<td><?php echo htmlentities($row['Auditeur']);?></td>
<td><?php echo htmlentities($row['Afdeling']);?></td>
<td><?php echo htmlentities($row['PostingDate']);?></td>
<td><?php echo htmlentities($row['Week']);?></td>
<td><?php echo htmlentities($row['Zone']);?></td>
<td><?php echo htmlentities($row['Stand']);?></td>
<td><?php echo htmlentities($row['NOKOK01']);?></td>
<td><?php echo htmlentities($row['Results']);?></td>
<td><?php echo htmlentities($row['NOKOK02']);?></td>
<td><?php echo htmlentities($row['Results2']);?></td>
<td><?php echo htmlentities($row['NOKOK03']);?></td>
<td><?php echo htmlentities($row['Results3']);?></td>
<td><?php echo htmlentities($row['Bericht']);?></td>
<td><button class="btn btn-info btn-xs"><span class="glyphicon glyphicon-pencil"></span></button></td>
<td><button class="btn btn-danger btn-xs" onclick="return confirm('Wil je bestand echt verwijderen?');"><span class="glyphicon glyphicon-trash"></span></button></td>
</tr>
<?php
// for serial number increment
$cnt++;
}
?>
</tbody>
</table>
here is my export.php code
<?php
//export.php
$connect = mysqli_connect("localhost", "root", "", "oopscrud02");
$output = '';
if(isset($_POST["export"]))
{
$query = "SELECT * FROM tblusers";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '
<table class="table" bordered="1">
<tr>
<th>#</th>
<th>Afdeling</th>
<th>Invoerdatum</th>
<th>Week</th>
<th>Zone</th>
<th>Stand</th>
<th>Zijn alle overbodeige gereedschappen / materialen van de werkpost verwijderd / geïdentificeerd? ( sleutel, bouten / moeren,.... )</th>
<th>Opgeslagen foto nr1</th>
<th>Is er rommel aanwezig op de werkpost ( bekertjes, kledij, flesjes,....)</th>
<th>Opgeslagen foto nr2</th>
<th>Zijn vervallen / niet geautoriseerde documenten verwijderd?</th>
<th>Opgeslagen foto nr3</th>
<th>Opmerking</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["Auditeur"].'</td>
<td>'.$row["Afdeling"].'</td>
<td>'.$row["PostingDate"].'</td>
<td>'.$row["Week"].'</td>
<td>'.$row["Zone"].'</td>
<td>'.$row["Stand"].'</td>
<td>'.$row["NOKOK01"].'</td>
<td>'.$row["Results"].'</td>
<td>'.$row["NOKOK02"].'</td>
<td>'.$row["Results2"].'</td>
<td>'.$row["NOKOK03"].'</td>
<td>'.$row["Results3"].'</td>
<td>'.$row["Bericht"].'</td>
</tr>
';
}
$output .= '</table>';
header('Content-Type: application/xls');
header('Content-Disposition: attachment; filename=Sorterend form.xls');
echo $output;
}
}
?>
I suggest you to use javascript library, it work for me
Install excell javascript and FileSaver for saving file
Adding 2 library
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js"></script>
XLX Js
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.14.1/xlsx.full.min.js"></script>
The script
<script>
$('#download-btn').on('click', function(){
var wb = XLSX.utils.table_to_book(document.getElementById('my-table'),{sheet: "Sheet name"})
var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: true, type: 'binary'});
function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i = 0; i < s.length; i++) {
view[i] = s.charCodeAt(i) & 0xFF;
}
return buf;
}
saveAs(new Blob([s2ab(wbout)], {type:"application/octet-stream"}), 'test.xlsx');
})
</script>
Maybe the easiest way is to use DataTables.
See example: https://datatables.net/extensions/buttons/examples/initialisation/export.html
After that you can simply use css and make it look as you want.

Xampp doesn't recognize <? tag

Today I needed to do some changes on my website so I downloaded the whole site to my computer, changed the IP's and login details and the website is working.
But, when I went to a page, I press the button and nothing happens, and the same button is working on the webhost.
This is the code I'm using (exactly the same on the webhost that is working):
if($serverSettings['itemshop']) {
if(isset($_GET['p']) && checkInt($_GET['p'])) {
$sqlCmdS="SELECT * FROM ".SQL_HP_DB.".is_items WHERE kategorie_id='".$_GET['p']."' AND anzeigen='J' ORDER BY preis ASC, vnum ASC";
}
else {
$sqlCmdS="SELECT * FROM ".SQL_HP_DB.".is_items WHERE anzeigen='J' ORDER BY preis DESC, vnum DESC";
}
?>
<div id="isleft">
<h2>Categorías</h2><br/>
<ul>
<?PHP
$sqlCmd = "SELECT * FROM ".SQL_HP_DB.".is_kategorien WHERE anzeigen='J' ORDER BY id ASC;";
$sqlQry = mysql_query($sqlCmd,$sqlHp);
while($getKats = mysql_fetch_object($sqlQry)) {
echo'<li>'.$getKats->titel.'</li>';
}
?>
</ul>
</div>
<div id="isright">
<table>
<?PHP
$sqlQry = mysql_query($sqlCmdS,$sqlHp);
$counter = 1;
while ($getItems = mysql_fetch_object($sqlQry)) {
$aktItem = compareItems($getItems->vnum);
$aktItem1 = compareItems($getItems->id);
$nome = compareItems($getItems->nome);
$itemStufe = (checkInt($aktItem['stufe'])) ? "+".$aktItem['stufe'] : '';
//$itemStufe1 = (checkInt($aktItem1['stufe'])) ? "+".$aktItem1['stufe'] : '';
?>
<tr>
<th colspan="2" class="topLine"><?= $nome['item'] ?> (<b><?= $getItems->count ?>x</b>) (<b><?= $getItems->preis ?> Coins</b>)</th>
</tr>
<tr>
<td class="isImg">
<?PHP
if(!empty($getItems->bild)) echo'<img src="./is_img/'.$getItems->bild.'.png" title="'.$aktItem['item'].'" alt="'.$aktItem['item'].'"/>';
?>
</td>
<td class="tdunkel"><?= $getItems->beschreibung ?></td>
</tr>
<tr>
<td colspan="2" class="isBuy">
<select id ="escolha<? echo $counter ?>">
<option value="">Escolhe...</option>
<option value="eu">Para mim</option>
<option value="outro">Para outro jogador</option>
</select><button onclick="confirmacao(escolha<? echo $counter; ?>,<? echo $getItems->id ?>,<? echo $getItems->preis; ?>)" title="Vais gastar <? echo $getItems->preis; ?> moedas">Comprar</button>
</td>
</tr>
<?PHP
$counter++;
}
?>
</table>
</div>
<script>
function confirmacao(escolha,id,preco)
{
//var val = escolhida.options[escolhida.selectedIndex].value;
switch(escolha.options[escolha.selectedIndex].value)
{
case "eu":
function confirma_compra(id,preco)
{
var ask = window.confirm("Queres mesmo comprar?\nIrão ser removidas "+preco+" moedas da tua conta!");
if (ask)
{
document.location.href = './is_buy-'+id+'.htm';
}
}
return confirma_compra(id,preco)
break;
case "outro":
document.location.href = './is_buy_outro-'+id+'.htm';
break;
case "":
alert("Tens de selecionar uma opção!");
break;
default:
alert("test");
}
return false;
}
</script>
And, this happens on the button's tooltip: https://prnt.sc/ff9mka
Thanks in advance
As I can see on your screenshot, they're showing you "<? echo ... ?>"
The problem are who newer versions of PHP have deprecated the shorttags. You need to change all tags <? with the complete one: <?php

How to delete row of table with a button inside

I have a table generated with The foreach construct, on each <tr> there is a delete button inside. I want to delete the row containing the button (by the ID) but all I've done is delete the last row (the last ID) that was saved and not the desired.
This is a part of my HTML code:
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<table class="Pizarra" id="pizarra" cellspacing="0px";>
<tr class="trThDos">
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tbody>
<!-- Comienza PHP -->
<?php
$i = 0;
foreach ($resultados as $fila)
{
?>
<tr>
<input type="hidden" name="id" value="<?php echo $fila['ID']; ?>" />
<td class="tdTurno"><?php echo '#' . ++$i ?></td>
<td class="tdImg">
<?php echo $fila ['value'];
switch ($fila['value'])
{
case "0":
echo "<img src='./img/consulta-56-2.png'";
break;
case "1":
echo "<img src='./img/shot-56-2.png'";
break;
case "2":
echo "<img src='./img/ta-56-2.png'";
break;
case "3":
echo "<img src='./img/cert-56-2.png'";
break;
default:
echo "Hubo un error en la selección";
break;
} ?>
</td>
<td>
<?php echo $fila ['nombre']; ?>
</td>
<td class="tdHr">
<?php echo $fila ['hora']; ?>
</td>
<td>
<input type="submit" class="btnBorrar" name="btnBorrar" value="X">
</td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
PHP code:
<?php
// ----------- CONEXIÓN ------------------
try {
$conexion = new PDO('mysql:host=localhost;dbname=farmacia', 'Emm', ' ');
$conexion->exec("set names utf8");
//echo "Conexión OK <br />";
}catch(PDOException $e){
echo "Error: " . $e->getMessage();
die();
}
// ----------- TERMINA CONEXIÓN -----------------
if(isset($_POST['btnBorrar'])){
$id = $_POST['id'];
$statement = $conexion->prepare("DELETE FROM eventos WHERE ID = $id");
$statement->execute();
//fetchAll' es clave para que invoque (llame) TODOS los elementos
$resultados = $statement->fetchAll();
header("Location:index.php");
$conexion = null;
}
?>
Use GET method instead of POST
In your HTML instead of using submit button use link as shown in below
X
In the delete.php do like following
<?php
if(isset($_GET['id'])){
//get the id into php variable like below
$id = $_GET['id'];
//sql query to delete with id variable in where clause
}
?>
Hope this work!!!
Try with below code..
HTML
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<table class="Pizarra" id="pizarra" cellspacing="0px";>
<tr class="trThDos">
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tbody>
<!-- Comienza PHP -->
<?php
$i = 0;
foreach ($resultados as $fila) {
?>
<tr id="row_id_<?php echo $fila['ID']; ?>">
<td class="tdTurno"><?php echo '#' . ++$i ?></td>
<td class="tdImg"><?php echo $fila ['value'];
switch ($fila['value']){
case "0":
echo "<img src='./img/consulta-56-2.png'";
break;
case "1":
echo "<img src='./img/shot-56-2.png'";
break;
case "2":
echo "<img src='./img/ta-56-2.png'";
break;
case "3":
echo "<img src='./img/cert-56-2.png'";
break;
default:
echo "Hubo un error en la selección";
break;
} ?></td>
<td><?php echo $fila ['nombre']; ?></td>
<td class="tdHr"><?php echo $fila ['hora']; ?></td>
<td><input type="button" class="btnBorrar" name="btnBorrar" value="X" onClick="delete_row(<?php echo $fila['ID']; ?>)"></td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
JavaScript
function delete_row(delete_id) {
$.ajax({
type: "POST",
url: 'delete_row.php',
data: 'delete_id='+delete_id,
success: function(data_respones){
$("#row_id_"+delete_id).remove();
}
});
}
delete_row.php
<?php
// ----------- CONEXIÓN ------------------
try {
$conexion = new PDO('mysql:host=localhost;dbname=farmacia', 'Emm', ' ');
$conexion->exec("set names utf8");
//echo "Conexión OK <br />";
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
die();
}
if(isset($_POST["delete_id"])){
//do delete stuff
$statement = $conexion->prepare("DELETE FROM eventos WHERE ID = $id");
$statement->execute();
}
?>
Instead of using POST method, use GET and give your delete button a link like
yourscript.php?delete={ID}
and handle your id like
$deleteId = (int)$_GET["delete"];
and
if(isset($deleteId)){
//do delete stuff
$statement = $conexion->prepare("DELETE FROM eventos WHERE ID = $deleteId");
$statement->execute();
//fetchAll' es clave para que invoque (llame) TODOS los elementos
$resultados = $statement->fetchAll();
}
Replace your hidden input field with this;
<a href="yourscript.php?delete=<?php echo $fila['ID']; ?>">Delete me</>

Error in sql query with php and mysql?

I got this error
You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near '' at line 1
and here is my code
<?php
$titulo = "Baja de usuario";
require "conexion.php";
$usu_nombre = $_POST["usu_nombre"];
$usu_id = $_POST["usu_id"];
$sql = "DELETE FROM usuarios WHERE usu_id = ".$usu_id;
$resultado = mysqli_query($link, $sql) or die(mysqli_error($link));
$chequeo = mysqli_affected_rows($link);
include "encabezado.php";
?>
Can't really find the syntax error there, any idea?
the $_POST["usu_id"] comes from here:
$titulo = "Formulario de baja- Usuarios - Proyecto integrador";
require "conexion.php";
$usu_id = $_GET["usu_id"];
$sql = "SELECT usu_id, usu_login ,usu_clave, usu_nombre, usu_email FROM usuarios WHERE usu_id = ".$usu_id;
$resultado = mysqli_query($link, $sql) or die(mysqli_error($link));
?>
<?php include "encabezado.php"; ?>
</head>
<body>
<div id="top"><img src="imagenes/top.png" alt="encabezado" width="980" height="80"></div>
<div id="nav">
<?php include "menu.php"; ?>
</div>
<div id="main">
<h1><?php echo $titulo ; ?></h1>
<!-- inicio del desarrollo -->
<form action = "baja-usuario.php" method = "post" onsubmit = "return confirmarBaja()">
<table id="paneles">
<tr>
<th colspan ="5">Se eliminara el siguiente usuario</th>
</tr>
<tr>
<th>Id</th>
<th>Login</th>
<th>Clave</th>
<th>Nombre</th>
<th>Email</th>
</tr>
<?php while($fila = mysqli_fetch_assoc($resultado)){ ?>
<tr>
<td class = "lista"><?php echo $fila["usu_id"] ;?></td>
<td class = "lista"><?php echo $fila["usu_login"]; ?></td>
<td class = "lista"><?php echo $fila["usu_clave"] ;?></td>
<td class = "lista"><?php echo $fila["usu_nombre"] ;?></td>
<td class = "lista"><?php echo $fila["usu_email"] ;?></td>
</tr>
<?php } ?>
<tr>
<td><input type= "hidden" name = "usu_id" value = "<?php echo $fila["usu_id"]; ?>"></td>
<td><input type= "hidden" name = "usu_nombre" value = "<?php echo $fila["usu_nombre"]; ?>"></td> <!-- el input type hidden no renderiza el valor pero si sirve para pasarlo como parametro en el FROM -->
</tr>
<tr>
<td colspan = "2" class ="centrar"><input type = "submit" value = "Eliminar"></td>
</tr>
</table>
</form>
and the usu_id from the : <td class = "lista"><?php echo $fila["usu_id"] ;?></td> displays correctly, showing the ID
The error was that i was using <?php while($fila = mysqli_fetch_assoc($resultado)){ ?> and so the usu_id the form send to the POST, was empty beacuse of the msqli_fetch_assoc

Categories