У меня есть база данных, заполненная идентификаторами сотрудника и соответствующими именами сотрудников для каждого идентификатора сотрудника. Есть ли способ поиска массива для идентификаторов сотрудников из базы данных? Google не помогает мне, я думаю, потому что я не уверен, как сложить мой поиск.Поиск массива значений из базы данных
Моя идея - иметь что-то вроде array_search ($ empID, $ currentArray). А затем прокрутите каждый идентификатор сотрудника из базы данных и сравните его с $ currentArray? Я сомневаюсь, что это самый эффективный способ, но я все еще участвую, поэтому любая помощь будет оценена по достоинству. Если кто-то захочет потратить некоторое время, чтобы помочь мне с этим, я могу разместить дополнительную информацию. Благодаря!
Edit Вот мой код, если кому-то интересно:
<?php
//this variable tells us how many drupal nodes or 'paystub pages' we need to create
$nodeCount = 0;
$i = 0;
//needed for creating a drupal node
//for this code to work this script must be run from the root of the drupal installation
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if ($handle = opendir('/var/www/html/pay.mistequaygroup.com/upload'))
{
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$nodeCount++;
//We convert the pdf documents into text documents and move put them in the converted folder
$command = "pdftotext /var/www/html/pay.mistequaygroup.com/upload/" . $file . " /var/www/html/pay.mistequaygroup.com/upload/converted/" . $file . ".txt";
//Execute the command above
$output = exec($command);
//mark all the spots that TO THE ORDER OF shows up
//echo array_search("TO THE ORDER OF", $currentArray);
//echo $userName;
//extract the employees name
//print_r($currentArray);
//echo '<pre>';
//echo array_search("DATE AMOUNT", $currentArray);
//echo '</pre>';
}
}
closedir($handle);
}
//subtract two because the folders "array" and "converted" are included because PHP does not differentiate
//between folders and files
$nodeCount = $nodeCount - 2;
echo "<br />";
echo "I counted $nodeCount pdf files";
echo "<br />";
//open the directory
if ($handle2 = opendir('/var/www/html/pay.mistequaygroup.com/upload/converted'))
{
//check to see if we have reached the last file of our directory, if not stay in loop
while (false !== ($currentText = readdir($handle2)))
{
//filter out files named . and ..
if ($currentText != "." && $currentText != "..")
{
//Create a file for array to be printed to
$createArray = fopen("/var/www/html/pay.mistequaygroup.com/upload/arrays/" . $currentText . ".txt", "w+") or die ("Cannot find file to create array, ID 2");
//read the file we are on from the loop into the array
$currentArray = file("/var/www/html/pay.mistequaygroup.com/upload/converted/" . $currentText, FILE_SKIP_EMPTY_LINES) or die ("Cannot find file to create array, ID 1");
//$countArray = array_search(". . . . . . . . . .", $currentArray);
//echo $countArray;
//print array to .txt file for debugging purposes
$out = print_r($currentArray, true);
fwrite($createArray, $out);
fclose($createArray);
//Loop?
array_search($empID, $currentArray);
//need to loop through the array we are on, looking for numbers that match the employee ID's
//OR we might have to search for names within a string of text and then get the corresponding ID for that user from the database?
//brainstorming
$query = SELECT * FROM `profile_values` WHERE `fid` = 2 AND `value` = $employeeID;
//DOES NOT WORK AS EXPECTED
$indexEmpid = 0;
foreach ($currentArray as $value)
{
//set the value to 28 and it doubles each time the loop runs so there is no need to add 28 each time
//every 28th index in our array is an employee id
$indexEmpid = $indexEmpid + 28;
$currentEmployeeID = $currentArray[$indexEmpid];
echo "<br />";
echo "Employee ID's found: $currentEmployeeID";
//echo "Employee ID's found: $currentArray[$indexEmpid]";
echo "<br />";
echo "IndexEmpid: $indexEmpid";
}
}
}
}
?>
Извините, меня не было достаточно ясно. Что действительно происходит здесь, так это то, что я пытаюсь импортировать paystubs. Я делаю это, преобразовывая файл PDF в txt, а затем читаю txt-файл в массив в PHP. Я не могу просто перейти на каждую 28-ю строку, например, и получить идентификатор сотрудника, поскольку идентификаторы не являются каждым 28-м индексом в массиве. Поэтому я решил, что следующий лучший способ - найти идентификаторы. У меня есть база данных drupal, каждое имя пользователя имеет идентификатор сотрудника, связанный с ним. Im ищет, чтобы искать мой массив, который является paystub для соответствующего идентификатора сотрудника из моей базы данных. Если это имеет смысл. – Hus