Good day I want to add Filter for specific record based on fetching array emp_id but my code doesnt seem to work im just new to phpmaker , please help thank you.
$unit=CurrentUserInfo("unit");
if ($userlevel == 1) {
$empid = ExecuteRows("SELECT emp_id FROM simc_users WHERE unit='$unit'");
$empids=['$empid'];
foreach ($empids as $emp_id) {
AddFilter($filter, "emp_id = '$emp_id'");
}
};
if ($userlevel == 1) { // ← Where is $userlevel from?
$empid = ExecuteRows(“SELECT emp_id FROM simc_users WHERE unit=‘$unit’”); // ← ExecuteRows() returns an array of records
$empids=[‘$empid’]; // ← Wrong syntax
foreach ($empids as $emp_id) {
AddFilter($filter, “emp_id = ‘$emp_id’”); // ← This adds filter by “AND”, not “OR”
}
}
$unit=CurrentUserInfo("unit");
if ($userlevel == 1) { // Assuming $userlevel is defined elsewhere
$empids = ExecuteRows("SELECT emp_id FROM simc_users WHERE unit='$unit'"); // Assuming ExecuteRows() returns an array of records
$filterConditions = []; // Initialize an array to store filter conditions
foreach ($empids as $emp_id) {
$filterConditions[] = "emp_id = '$emp_id[emp_id]'"; // Assuming 'emp_id' is the column name in the database
}
// Join filter conditions with 'OR'
$filter = implode(' OR ', $filterConditions);
AddFilter('emp_id', $filterConditions);
};
but I get this error
D:\xampp\htdocs\bio\models\SimcOffduty.php(1432): PHPMaker2024\AMS\AddFilter(): Argument #1 ($filter) cannot be passed by reference
Already updated the code but no error but no records found
if ($userlevel == 1) { // Assuming $userlevel is defined elsewhere
$empids = ExecuteRows("SELECT emp_id FROM simc_users WHERE unit='$unit'"); // Assuming ExecuteRows() returns an array of records
$filterConditions = []; // Initialize an array to store filter conditions
foreach ($empids as $emp_id) {
$filterConditions[] = "emp_id = '$emp_id[emp_id]'"; // Assuming 'emp_id' is the column name in the database
}
// Join filter conditions with 'OR'
$filter = implode(' OR ', $filterConditions);
// Assuming AddFilter function accepts at least two arguments (fieldName and filterValue)
// Modify this according to your actual implementation in PHPMaker2024\AMS namespace
foreach ($filterConditions as $filterCondition) {
AddFilter($filter, $filterCondition);
}
};
Finally fixed the code guys thank you for your help
this is the final code finally able to select data based on the unit of users and get the ids as filter condition
$unit=CurrentUserInfo("unit");
if ($userlevel == 1) { // Assuming $userlevel is defined elsewhere
$empids = ExecuteRows("SELECT emp_id FROM simc_users WHERE unit='$unit'"); // Assuming ExecuteRows() returns an array of records
$filterConditions = []; // Initialize an array to store filter conditions
foreach ($empids as $emp_id) {
$filterConditions[] = "emp_id = '" . $emp_id["emp_id"] . "'"; // Assuming 'emp_id' is the column name in the database
}
// Join filter conditions with 'OR'
$filters = implode(' OR ', $filterConditions);
foreach ($filterConditions as $filterCondition) {
AddFilter($filter, $filters);
}
};