你能帮我解释一下这段代码的正确语法吗?我想使用表前缀变量{$ wpdb-> prefix},但我不知道如何正确转义双引号。
$the_query =
"
SELECT
{$wpdb->prefix}frm_items.id AS store_id,
MAX(IF({$wpdb->prefix}frm_item_metas.field_id = 224, {$wpdb->prefix}frm_item_metas.meta_value,\"\")) prvni,
MAX(IF({$wpdb->prefix}frm_item_metas.field_id = 225, {$wpdb->prefix}frm_item_metas.meta_value,\"\")) druhy,
MAX(IF({$wpdb->prefix}frm_item_metas.field_id = 226, {$wpdb->prefix}frm_item_metas.meta_value,\"\")) treti,
FROM
{$wpdb->prefix}frm_items,
{$wpdb->prefix}frm_item_metas
WHERE
{$wpdb->prefix}frm_items.id = {$wpdb->prefix}frm_item_metas.item_id
AND
{$wpdb->prefix}frm_item_metas.field_id
IN
( 224,225,226 )
GROUP BY
{$wpdb->prefix}frm_items.id
ORDER BY
{$wpdb->prefix}frm_item_metas.field_id = 224 DESC,
{$wpdb->prefix}frm_item_metas.field_id = 225 DESC,
{$wpdb->prefix}frm_item_metas.field_id = 226 DESC
"
;
答案 0 :(得分:1)
也许你应该试试这个:
$table_name = $wpdb->prefix . 'frm_items';
$query = "SELECT $table_name.id AS store_id.... "
答案 1 :(得分:0)
喜欢这个?
$theQuery = "SELECT ".$wpdb->prefix."frm_items.id AS store_id,
MAX(IF(".$wpdb->prefix."frm_item_metas.field_id = 224, ".$wpdb->prefix."frm_item_metas.meta_value,\"\")) prvni,
MAX(IF(".$wpdb->prefix."frm_item_metas.field_id = 225, ".$wpdb->prefix."frm_item_metas.meta_value,\"\")) druhy,
MAX(IF(".$wpdb->prefix."frm_item_metas.field_id = 226, ".$wpdb->prefix."frm_item_metas.meta_value,\"\")) treti,
FROM
".$wpdb->prefix."frm_items,
".$wpdb->prefix."frm_item_metas
WHERE
".$wpdb->prefix."frm_items.id = ".$wpdb->prefix."frm_item_metas.item_id
AND
".$wpdb->prefix."frm_item_metas.field_id
IN
( 224,225,226 )
GROUP BY
".$wpdb->prefix."frm_items.id
ORDER BY
".$wpdb->prefix."frm_item_metas.field_id = 224 DESC,
".$wpdb->prefix."frm_item_metas.field_id = 225 DESC,
".$wpdb->prefix."frm_item_metas.field_id = 226 DESC;