松弛,php 和 json - 迭代应用程序选择的有效标记

slack, php and json - Valid Markup for iterating app selections

我一直在尝试创建一个 slack 应用程序,它获取产品名称和 sku 的基本信息,并将其放在出现在 slack 中的 select 框中。不幸的是,当我尝试使用循环迭代时,我填充有效 json 的代码在某处出错了。

有效Json在这里:

{
    "text": "Great! You want to find something!",
    "attachments": [
        {
            "text": "Please type what you want to find",
            "fallback": "Sorry! Cant do that at the moment!",
            "callback_id": "cg_selectproduct",
            "color": "#3AA3E3",
            "attachment_type": "default",

            "actions": [

                {
                    "name": "cg_choice",
                    "text": "Find Product",
                    "type": "select",
                    "options": [
                        {
                                "text": "option1",
                                "value": "option1"
                        },

                        {
                                "text": "option2",
                                "value": "option2"
                        },
                        {
                                "text": "option3",
                                "value": "option3"
                        }]
                }
            ]
        }
    ]
}

这在没有迭代的情况下工作得很好。如果我告诉应用程序到这里,我没有问题。它正确显示所有选项。

无效PHP

$check = ($dbh->prepare("SELECT * FROM product_list WHERE FAMILY='PARENT'"));
$check->execute();
$row = $check->fetchAll();
// execute a pdo search to find all product parents

$jsonInput = "";
foreach($row as $rows){
$jsonInput .= '"text"=>"' . $rows['PRODUCT_NAME'] . '", "value" => "' . $rows['SKU'] . '",';
}
$jsonInput = rtrim($jsonInput, ',');
//Create an iterative string which will contain the product names and skus, removing the comma at the end.

header('Content-Type: application/json');
//Set the content type to json


$optionSelect = array(
    "text" => "Great! You want to find something!",
    "attachments" =>array(
            "text" => "Please type what you want to find",
            "fallback" => "Sorry! Cant do that at the moment!",
            "callback_id" => "cg_selectproduct",
            "color"=> "#3AA3E3",
            "attachment_type" => "default",

            "actions" => array(
                    "name" => "cg_choice",
                    "text" => "Find Product",
                    "type" => "select",
                    "options" => array($jsonInput)
                        )

           )

    );
//Create and itterate the options for the selection so it's populated

print_r(json_encode($optionSelect));
//print to show json

我不是 100% 确定我哪里出了问题。也许我对次要部分的考虑有点太多了。这里的任何人都可以帮助我解决我要去的地方吗?

$jsonInput = [];
foreach($row as $rows) {
    $jsonInput[] = array(
        'text' => $rows['PRODUCT_NAME'],
        'value' => $rows['SKU']
    );
}

// ...........

"options" => $jsonInput