mysql 当我添加产品到woocommerce 4.4.1错误消息出来

ojsjcaue  于 2023-06-21  发布在  Mysql
关注(0)|答案(2)|浏览(131)

当我尝试将产品添加到wordpress-> woocomerce时,出现错误消息:
WordPress数据库错误:[您的SQL语法中有错误;检查与您的MySQL服务器版本对应的手册,以获得正确的语法使用')或p.product_id = 30582或g.apply_to = 'all' GROUP BY g.id ORDER BY g' at line 5]

SELECT 
    g.*
    , GROUP_CONCAT(DISTINCT c.category_id) as `categories`
    , GROUP_CONCAT(DISTINCT p.product_id) as `products` 
FROM wpav_za_groups as g 
    LEFT JOIN wpav_za_categories_to_groups as c ON c.group_id = g.id 
    LEFT JOIN wpav_za_products_to_groups as p ON p.group_id = g.id 
WHERE 
    c.category_id IN () 
    OR p.product_id = 30582 
    OR g.apply_to = 'all' 
GROUP BY g.id 
ORDER BY g.priority ASC

你能帮忙查一下是什么问题吗?

avwztpqn

avwztpqn1#

IN子句中缺少文本或数据

c.category_id IN ('test1','teswt2')

代替text1和test2,您必须输入自己的文本或数据

SELECT 
    g.*
    , GROUP_CONCAT(DISTINCT c.category_id) as `categories`
    , GROUP_CONCAT(DISTINCT p.product_id) as `products` 
FROM wpav_za_groups as g 
    LEFT JOIN wpav_za_categories_to_groups as c ON c.group_id = g.id 
    LEFT JOIN wpav_za_products_to_groups as p ON p.group_id = g.id 
WHERE 
    c.category_id IN ('test1','teswt2') 
    OR p.product_id = 30582 
    OR g.apply_to = 'all' 
GROUP BY g.id 
ORDER BY g.priority ASC
jslywgbw

jslywgbw2#

// Assuming you have an array of category IDs ($categoryIDs) and a product ID 
($productID)
$categoryIDs = array(1, 2, 3); // Replace with your actual category IDs
$productID = 30582; // Replace with your actual product ID

// Prepare the category IDs for the SQL query
$categoryIDsString = implode(', ', $categoryIDs);

// Perform the database query with the modified SQL query
$query = "SELECT 
g.*,
GROUP_CONCAT(DISTINCT c.category_id) as `categories`,
GROUP_CONCAT(DISTINCT p.product_id) as `products`
FROM wpav_za_groups as g
LEFT JOIN wpav_za_categories_to_groups as c ON c.group_id = g.id
LEFT JOIN wpav_za_products_to_groups as p ON p.group_id = g.id
WHERE
c.category_id IN ($categoryIDsString)
OR p.product_id = $productID
OR g.apply_to = 'all'
GROUP BY g.id
ORDER BY g.priority ASC";

// Execute the query and handle the results
$result = $wpdb->get_results($query);

相关问题