Input field feeding mysql HAVING clause of a raw function

Input field feeding mysql HAVING clause of a raw function

carrarachristophecarrarachristophe Posts: 122Questions: 28Answers: 2
edited February 22 in DataTables 2

Hello,

I am feeding a Datatable with a mysql SELECT raw function.

<?php
// Include config file
require_once "config.php";

// Attempt select query execution
$sql = "
SELECT
....
GROUP BY 
    patrimoine_instruments.`instrument`
HAVING 
    (
        quantite <> 0 
    AND 
        patrimoine_transactions.datetime <= '2024-12-31'
    )
";
if($result = $pdo->query($sql)){
if($result->rowCount() > 0){
while($row = $result->fetch()){     ?>

I am trying to replace '2024-12-31' by the value of an input field that I included above the datatable:

<h3 class="pull-left">Mon patrimoine au <input type="date" id="max-date" value="<?php echo date('Y-m-d'); ?>" data-date-format="dd-mm-yyyy"></h3>
<table id="patrimoines" class="display compact cell-border nowrap" width="100%">

Knowing that the datatable would have to reload everytime the value changes.

Did anyone implement something similar to that?

Answers

  • kthorngrenkthorngren Posts: 21,681Questions: 26Answers: 5,019
    edited February 22

    Not sure I fully understand what you are asking for. It sounds like you want to send the input value to the server to filter the results for the Datatable. If this is the case then use ajax.data as a function, like this example, to send the value as a parameter. Get the parameter in your server script to use in the SQL query.

    Kevin

Sign In or Register to comment.