Input field feeding mysql HAVING clause of a raw function
Input field feeding mysql HAVING clause of a raw function

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
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 useajax.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
Hi Kevin,
Thank you for your suggestion but I am not sure how I can use it for my need.
I had a look to https://datatables.net/forums/discussion/comment/72061/#Comment_72041 and https://www.w3schools.com/php/php_mysql_prepared_statements.asp but am not sure it is the right track.
Sorry, I guess I don't understand your requirements. Please provide more details about your solution, requirements and the problem you are trying to solve.
Kevin
I interpreted your question the same way Kevin has. Use
ajax.data
to get the value from your input element, and then use that as part of your query.Is the problem that you don't know how to use the value as part of the query? For that, you should refer to the PHP PDO documentation for binding values. You'd get the value from
$_REQUEST
.Allan