我使用ZOHO Inventory API创建商品组并将商品从数据库添加到通过cURL传递的JSON字符串中 当我回显结果时,它显示JSON, 问题是它不会显示从数据库中提取的第一个条目,并导致json代码iteself出现问题。
这是在提取第一个产品结果并将其添加到项目部分之前应显示的代码
{
"group_name": "Dry Fruits",
"brand": "",
"manufacturer": "",
"unit": "Kg",
"description": "Dry Fruits - Dry Fruits and Nuts",
"attribute_name1": "",
"product_type": "goods",
"items": [
{
因此,最终要通过CURL传递的JSON字符串中的完整条目看起来像这样
{
"group_name": "Dry Fruits",
"brand": "",
"manufacturer": "",
"unit": "Kg",
"description": "Dry Fruits - Dry Fruits and Nuts",
"attribute_name1": "",
"product_type": "goods",
"items": [
{
"name": "All Spice Pimento Ground-Poly Bag Bulk-25Kg",
"rate": 0,
"purchase_rate": 0,
"reorder_level": 10,
"initial_stock": 50,
"status": "active",
"initial_stock_rate": 1.5,
"sku": "2362-072-052-00",
"upc": 2362,
"ean": 1005,
"isbn": 502185801005,
"image_name": "/images/502185801001.png",
"image_type": "png",
"attribute_option_name1": ""
}
],
"attributes": [
{
}
]
}
显然,这些项目将有多个条目。 我只是感到困惑,为什么“组名”部分没有添加到第一项的JSON的第一行中 -这是完整的JSON输出https://shrib.com/?v=nc#uEL9I-RVLlAOKmNLhS9X
下面是我的PHP代码
$query = mysqli_query($dbc, "SELECT * FROM `products-full` GROUP BY `list_name` ASC");
while($res = mysqli_fetch_assoc($query)) {
$listname = $res['list_name'];
$pquery = mysqli_query($dbc,"SELECT * FROM `products-full` WHERE `list_name` = '$listname' LIMIT 5");
$prod = mysqli_fetch_assoc($pquery);
$itemcount = mysqli_num_rows($pquery);
$barcodefolder = "/images/";
$barcode = $barcodefolder.$prod['barcode'].".png";
$STRING = "{
\"group_name\": \"$listname\",
\"brand\": \"\",
\"manufacturer\": \"\",
\"unit\": \"Kg\",
\"description\": \"$listname - $res[cat]\",
\"attribute_name1\": \"\",
\"product_type\": \"goods\",
\"items\": [
";
$ic = 1;
do {
$isbn = $prod['barcode'];
$upc = $prod['product_code'];
$sku = $prod['cost_code'];
$product = $prod['product'].'-'.$prod['style_desc'].'-'.$prod['weight_desc'];
$seqno = $prod['sequence_no'];
if($ic != 5){ $next = ", \n"; } else { $next = "\n";}
echo "{
\"name\": \"$product\",
\"rate\": 0,
\"purchase_rate\": 0,
\"reorder_level\": 10,
\"initial_stock\": 50,
\"status\": \"active\",
\"initial_stock_rate\": 1.5,
\"sku\": \"$sku\",
\"upc\": $upc,
\"ean\": $seqno,
\"isbn\": $isbn,
\"image_name\": \"$barcode\",
\"image_type\": \"png\",
\"attribute_option_name1\": \"\"
}$next";
$ic++;
} while ($prod = mysqli_fetch_assoc($pquery)) ;
$endofgroup = "],
\"attributes\": [
{
}
]
},";
echo $endofgroup;
}
非常感谢