Skip to main content

no data in pdo statement

I have a problem with my table created with datatable and the sql query I make. The problem is that the result of the PDO query that I make with: min and: max does not work while if I replace the defined values ​​it gets results. I looked at the code structure but I don't find any problems and I hope you are luckier than me.

Below is the code:

$('.input-daterange input').each(function() {
  $.fn.datepicker.dates['it'] = {
      days: ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"],
      daysShort: ["D", "L", "M", "M", "G", "V", "S"],
      daysMin: ["D", "L", "M", "M", "G", "V", "S"],
      months: ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"],
      monthsShort: ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"],
      today: "Oggi",
      clear: "Annulla",
      format: "dd/mm/yyyy",
      titleFormat: "MM yyyy", /* Leverages same syntax as 'format' */
      weekStart: 1
  };
    $(this).datepicker({
    format: "dd-mm-yyyy",
    weekStart: 1,
    language: "it",
    orientation: "bottom left",
    clearBtn: true,
    autoclose: true,
    today:true
  }).datepicker("setDate", new Date());

});


$('#cercaFoglioCassa').click(function(){
  let min = $('#min').val();
  let max = $('#max').val();
    // DataTables initialisation
    var table = $('#foglioCassa').DataTable({
      "language": {
        url: 'https://cdn.datatables.net/plug-ins/1.10.25/i18n/Italian.json'
      },
      "processing": true,
      "serverSide": true,
      "order": [],
      "autoWidth": false,
      "ajax": {
        url: "action.php",
        type: "POST",
        data: {
          action: 'getCassa', min, max
        }
      },
      "columnDefs": [{
        "targets": [0,1,2,3,4,5,6,7,8,9],
        "orderable": false,
      }, ],
    });
$('#risultatoFiltro').css('display','block');

PHP code

if ($_POST['action'] === 'getCassa') {
    $min = date('Y-m-d', strtotime($_POST['min']));
    $max = date('Y-m-d', strtotime($_POST['max']));
    $stmt = $db->prepare('SELECT incassi.idIncasso,name, surname,polizze_RCA.tipo ,polizze_RCA.n_polizza,polizze_RCA.premio, incassi.idPolizza, t_compagnie.nome, t_company.compagnia, incassi.importo, incassi.tipoPagamento, incassi.data, incassi.sospeso FROM members, polizze_RCA, incassi, t_compagnie, t_company WHERE members.memberID = polizze_RCA.id_cliente AND polizze_RCA.id = incassi.idPolizza AND t_compagnie.id = polizze_RCA.id_compagnia AND t_company.id =polizze_RCA.id_ramo AND incassi.data BETWEEN :min AND :max');
    $stmt->execute(array(
        ':min' => $min,
        ':max' => $max
    ));
    $incassi = $stmt->fetchAll();
    foreach ($incassi as $i) {
     $sub_array = array();


            $sub_array[] = '<a href="update-incasso.php?idIncasso='.$i['idIncasso'].'">'.$i['idIncasso'].'</a>';
         $sub_array[] = date('d-m-Y', strtotime($i['data']));
         $sub_array[] = $i['name']. " " .$i['surname'];
         $sub_array[] = $i['tipoPagamento'];
         $sub_array[] = "€ ".$i['importo'];
         $sub_array[] = '<a href="polizza.php?idPolizza='.$i['idPolizza'].'&tipoPolizza='.$i['tipo'].'&nPolizza='.$i['n_polizza'].'&premio='.$i['premio'].'">'.$i['n_polizza'].'</a>';
         $sub_array[] = $i['nome'];
         $sub_array[] = $i['compagnia'];
         if ($i['sospeso'] === 'SI') {
             $sub_array[] = '<button type="button" class="btn btn-danger btn-sm"><i class="fas fa-check"></i></button>';
         }else {
             $sub_array[] = "";
         }

         $sub_array[] = '<button type="button" name="cancellaIncasso" class="btn btn-danger btn-sm cancellaIncasso" data-id="'.$i["id"].'"><i class="fas fa-times"></i></button>';
            $data [] = $sub_array;
     }
            $stmt = $db->prepare('SELECT count(*) as total_rows FROM incassi');
         $stmt->execute();
         $totalRows = $stmt->fetchAll();
         foreach ($totalRows as $tr) {
             $total_rows = $tr['total_rows'];
         }
    $output = array(
        "draw"              =>  intval($_POST["draw"]),
        "recordsTotal"      =>  $total_rows,
        'recordsFiltered' => $total_rows,
        "data"              =>  $data
    );
    echo json_encode($output);
}


source https://stackoverflow.com/questions/70115463/no-data-in-pdo-statement

Comments

Popular posts from this blog

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

The number of nodes and edges I calculated manually and by a method provided by networkx library dont match

I am trying to analyse a graph using networkx library in Python. I have implemented a function that returns the nodes and edges of that graph. After that I counted the number of nodes and edges by implementing the len() function for nodes and edges, which gave me 17 for both nodes and edges. However, when I used the method graph.number_of_nodes() of networkx library it gave me 53. My code: import pandas as pd import networkx as nx import matplotlib.pyplot as plt header_list = ["a","b","w"] E =pd.read_csv("aves-barn-swallow-contact-network.edges",sep=" ",header= None,names=header_list) # print(E.head()) # prints first few rows of the csv file G = nx.from_pandas_edgelist(E,"a","b",["w"]) nx.draw(G) plt.show() class GraphAnalyse: #finding nodes and edges def nodeEdge(self,Graph): nodes = Graph.nodes() edges = Graph.edges() ...