提前感谢您的帮助。
我正在用配方奶粉处理一点泡菜。我正在尝试创建一个页面模板,该模板将显示用户列表、usermeta表中的特定元数据+此外,我还想从我创建的表中提取数据。以下是表格结构的屏幕截图:https://www.screencast.com/t/X07XDr3Gy.
我的部分工作是获取用户名、姓氏和公司:
$sql = "
SELECT {$wpdb->users}.ID, firstname.meta_value as first_name, lastname.meta_value as last_name, webaria_company.meta_value as webaria_company,
FROM {$wpdb->users}
INNER JOIN (SELECT user_id, meta_value
FROM {$wpdb->usermeta} WHERE meta_key = \'first_name\') as firstname ON {$wpdb->users}.ID = firstname.user_id
INNER JOIN (SELECT user_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = \'last_name\') as lastname ON {$wpdb->users}.ID = lastname.user_id
INNER JOIN (SELECT user_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = \'webaria_company\') as webaria_company ON {$wpdb->users}.ID = webaria_company.user_id
";
$asuserlist = $wpdb->get_results($sql);
而且效果很好
但我试图从表attp2\\u as\\u score、列score\\u as中获取更多信息
$sql = "
SELECT {$wpdb->users}.ID, firstname.meta_value as first_name, lastname.meta_value as last_name, webaria_company.meta_value as webaria_company, score_as
FROM {$wpdb->users}, wattp2_as_score
INNER JOIN (SELECT user_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = \'first_name\') as firstname ON {$wpdb->users}.ID = firstname.user_id
INNER JOIN (SELECT user_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = \'last_name\') as lastname ON {$wpdb->users}.ID = lastname.user_id
INNER JOIN (SELECT user_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = \'webaria_company\') as webaria_company ON {$wpdb->users}.ID = webaria_company.user_id
INNER JOIN (SELECT score_as FROM wattp2_as_score WHERE approved=1) as scoreas ON {$wpdb->users}.ID = scoreas.user_id
";
$asuserlist = $wpdb->get_results($sql);
我得到一个错误:
WordPress数据库错误:[字段列表中的“score\\u as”列不明确]选择wattp2\\u用户。ID,名字。meta\\u值为first\\u name,lastname。meta\\u值作为姓氏,webaria\\u公司。meta\\u值为webaria\\u company,score\\u为wattp2\\u用户,wattp2\\u为\\u score内部联接(选择user\\u id,meta\\u值为wattp2\\u usermeta,其中meta\\u key=\'first\\u name\')作为wattp2\\u用户的firstname。ID=名字。user\\u id internal JOIN(从wattp2\\u usermeta中选择user\\u id,meta\\u value,其中meta\\u key=\'last\\u name\')作为wattp2\\u用户的lastname。ID=姓氏。user\\u id内部联接(从wattp2\\u usermeta中选择user\\u id,meta\\u value,其中meta\\u key=\'webaria\\u company\')作为wattp2\\u用户上的webaria\\u company。ID=webaria\\u公司。user\\u id内部连接(从wattp2\\u中选择score\\u as\\u score,其中approved=1)作为wattp2\\u用户上的scoreas。ID=分数。用户\\u id