简体   繁体   中英

Datatables - How can i use an array as SQL where clause

I'm trying to make a Datatable that dynamically loads data based on the user's settings.

On the server processing script

I have an array of branches owned by the current user.

$branchesOwned = $db->query('SELECT branchId FROM zapp_clt_branchesowner WHERE ownerId = ?', $ownerId)->fetchAll();

So far so good!

i tried to create a secondary array where i would store the branchId from the 1st array :

$whereArray = [];

foreach ($branchesOwned as $result) {
array_push($whereArray, $result['branchId']);
}

now on the SSP complex i have this:

//$whereAll = "status = 'B Activo' AND branchID IN ('1')"; <--- WORKING
$whereAll = "status = 'B Activo' AND branchID IN {$whereArray}"; // <--- NOT WORKING


echo json_encode(
SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, $whereResult = null, $whereAll)
);

As you can see if it write the array directly in the $whereAll it works

You can do something like this:

$idsAsString = sprintf("('%s')", implode("', '", $whereArray));

$whereAll = "status = 'B Activo' AND branchID IN $idsAsString"; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM