gpt4 book ai didi

php - 生成的 View 填充了 NULL

转载 作者:行者123 更新时间:2023-11-28 23:27:16 24 4
gpt4 key购买 nike

更新:问题似乎已解决,这是由于我在声明时使用了不同的小写而不是大写。但是,我现在面临一个问题,即 View “vw_formdatahard”只填充了多个“NULL”。我要疯了。

我有一个程序可以根据 Wordpress 和 Buddypress 数据库中的可用数据创建 View 。这在我的本地 Mamp 服务器上运行得很好,但每当我在我的托管服务器上调用该过程时都会给我一个错误。即使当我将整个数据库从本地服务器复制到在线服务器时,它仍然会返回错误。我不是 mysql 英雄,所以我要走到尽头了。为什么这不能运行?

The following query has failed: "CALL stp_FormQueryBuilder(); MySQL said: #1054 - Unknown column 'd.user_id' in 'field list'

BEGIN 


DECLARE sqlText text;

DROP VIEW IF EXISTS vw_FormDataRows;

CREATE VIEW vw_FormDataRows AS
SELECT d.user_id, f.name,
CASE WHEN left(f.name, 4) = 'FOTO' && LEFT(d.value, 9) = '/profiles' THEN CONCAT("/wp-content/uploads",d.value)
ELSE d.value END AS 'value'


FROM wp_bp_xprofile_fields AS F
LEFT JOIN wp_bp_xprofile_data AS D ON F.id = D.field_id
WHERE
parent_id = 0
AND group_id = 1
AND d.user_id IN(SELECT U.user_id FROM wp_usermeta AS U WHERE U.meta_key = 'wp_user_level' AND U.meta_value = '0')

ORDER BY d.user_id, f.id;

DROP TEMPORARY TABLE IF EXISTS temp1;

CREATE TEMPORARY TABLE temp1 (SELECT b.user_id, b.name, b.value
FROM (SELECT d.user_id, f.name, d.value
FROM wp_bp_xprofile_fields AS F
LEFT JOIN wp_bp_xprofile_data AS D ON F.id = D.field_id
WHERE
parent_id = 0
AND group_id = 1
AND d.user_id IN(SELECT U.user_id FROM wp_usermeta AS U WHERE U.meta_key = 'wp_user_level' AND U.meta_value = '0')
ORDER BY d.user_id, f.id ) AS B);


SET @sql = NULL;

SET group_concat_max_len = 4096;

SELECT GROUP_CONCAT(DISTINCT
CONCAT('MAX(CASE WHEN name = ', name,
' THEN value END) AS `', replace(name, ' ','_'), '`'))
INTO sqlText
FROM temp1;


DROP VIEW IF EXISTS vw_FormDataHard;

SET @sql = CONCAT('CREATE VIEW vw_FormDataHard AS SELECT user_id, ', sqlText, '
FROM vw_FormDataRows
GROUP BY user_id');


PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

DROP TEMPORARY TABLE IF EXISTS temp1;

END

最佳答案

您从未定义过别名 d 只是 D,它们是不同的,因为别名区分大小写。

关于php - 生成的 View 填充了 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38789646/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com