我想从数据库中检索NEW_COLUMN_1和NEW_COLUMN_2列的值,使用以下函数中NUMBER列中的不同CR号码:
function retrieveDistinctFilePaths(array $distinctCRNumbers, $database)
{
$filePaths = [];
echo "<pre>"; print_r($distinctCRNumbers); echo "</pre>"; // Line A
foreach ($distinctCRNumbers as $crNumber) {
$query = "
SELECT
NEW_COLUMN_1,
NEW_COLUMN_2
FROM
your_table_name
WHERE
NUMBER = '$crNumber'";
// 执行查询并从数据库中获取结果
$database->executeStatement($query);
// 从结果中获取行
$row = $database->fetchRow();
if ($row) {
$filePaths[$crNumber] = [
'NEW_COLUMN_1' => $row['NEW_COLUMN_1'],
'NEW_COLUMN_2' => $row['NEW_COLUMN_2']
];
}
}
echo "<pre>"; print_r($filePaths); echo "</pre>"; // Line Y
return $filePaths;
}
上述函数中的Line A打印如下内容:
Array
(
[0] => AUTH-GOOD-MORNING
[1] => GOOD-MORNING
)
上述函数中的Line Z输出(打印)如下内容。从Line Z的输出中可以看出,问题在于它没有根据Line A中的'GOOD-MORNING'数组值打印结果。
Array
(
[AUTH-GOOD-MORNING] => Array
(
[0] => Array
(
[NEW_COLUMN_1] =>
[NEW_COLUMN_2] =>
)
)
)
问题陈述:我想知道我需要在上述函数中进行哪些更改,以便Line Z根据Line A中的两个数组值打印值。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
function retrieveDistinctFilePaths(array $distinctCRNumbers, $database) { $filePaths = []; echo "<pre>"; print_r($distinctCRNumbers); echo "</pre>"; // Line A foreach ($distinctCRNumbers as $crNumber) { $query = " SELECT NEW_COLUMN_1, NEW_COLUMN_2 FROM your_table_name WHERE NUMBER = '$crNumber'"; // 执行查询并从数据库中获取结果 $database->executeStatement($query); // 获取当前CR号的所有行 $rows = $database->fetchAll(); // 获取所有行 foreach ($rows as $row) { $filePaths[$crNumber][] = [ 'NEW_COLUMN_1' => $row['NEW_COLUMN_1'], 'NEW_COLUMN_2' => $row['NEW_COLUMN_2'] ]; } } echo "<pre>"; print_r($filePaths); echo "</pre>"; // Line Z return $filePaths; }