0

I found a tutorial to use datatables using the server side but it has a nested if for case cases (if the search entry is empty, if it is ordered by columns, etc) and I would like to place it within a single stored procedure

https://www.webslesson.info/2017/01/php-pdo-ajax-crud-with-data-tables-and-bootstrap-modals.html

$query = '';
$query .= "SELECT * FROM empleados ";
if(isset($_POST["search"]["value"])){
    $query .= 'WHERE NombreEmpleado LIKE "%'.$_POST["search"]["value"].'%" ';
    $query .= 'OR ApellidoPat LIKE "%'.$_POST["search"]["value"].'%" ';
    $query .= 'OR Apellidomat LIKE "%'.$_POST["search"]["value"].'%" ';
}
if(isset($_POST["order"])){
    $query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].' ';
} else {
    $query .= 'ORDER BY IdEmpleado DESC ';
}
if($_POST["length"] != -1){
    $query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
Manuel Ruiz
  • 29
  • 1
  • 9
  • If you're asking the SO community to rewrite that PHP into a MySQL Stored Procedure don't expect the greatest of responses... if not, could you make it a little clearer exactly what the problem you're having is, please? – CD001 Jun 28 '19 at 15:59
  • It happens to me that I'm just seeing procedures stored in sql and I do not understand how to do them because if I use PHP it works fine but php sends parameters and I do not know how to send those parameters to the stored procedure – Manuel Ruiz Jun 28 '19 at 16:10
  • Here are [some reasons](https://stackoverflow.com/a/6369030/3986005) not to use stored procedures for this. – KIKO Software Jun 28 '19 at 16:54

0 Answers0