Mysqlテーブルはこのようなものです
NumberRenamed | CompanyName
---------------------
1 | a
2 | aa
3 | z
$_POST['transaction_partner_name']
2 つの値が含まれます。たとえばa
、 とz
このような結果が必要です
Array
(
[1] => a
[3] => z
)
これを試した
foreach($_POST['transaction_partner_name'] as $i => $post_transaction_partner_name) {
$placeholders .= '?,';
}
$placeholders = (rtrim( ($placeholders), ',' ));
try {
$stmt = $db->prepare("SELECT CompanyName, NumberRenamed
FROM 2_1_transactionpartners WHERE CompanyName IN ($placeholders)");
$stmt->execute( ($_POST['transaction_partner_name']) );
$stmt->bindColumn('CompanyName', $company_name);
$stmt->bindColumn('NumberRenamed', $number_renamed);
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
$result = compact("number_renamed", "company_name");
//$result = $company_name. $number_renamed;
echo '<pre>';
print_r($result);
echo '</pre>';
}
}
しかし、得る
Array
(
[number_renamed] => 1
[company_name] => a
)
またはa1
_$result = $company_name. $number_renamed;
これも試した
$arraytable = array();
while ($row = $stmt->fetchAll()) {
$arraytable[$row['NumberRenamed']] = $row['CompanyName'];
echo '<pre>';
print_r($arraytable);
echo '</pre>';
}
しかし得る
Array
(
[] =>
)
何を修正する必要があるかアドバイスしてください
アップデート
後$stmt->bindColumn('NumberRenamed', $number_renamed);
試した
$result = array();
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
$result = compact("number_renamed", "company_name");
$result[$row['number_renamed']] = $row['company_name'];
}
echo '<pre>', print_r($result), '</pre>';
得る
Array
(
[number_renamed] => 1
[company_name] => a
[] =>
)
1
それから試した
$result = array();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$result[$row['number_renamed']] = $row['company_name'];
}
echo '<pre>', print_r($result), '</pre>';
そして得る
Array
(
[] =>
)
1