I am trying to debug a SQL query, but I am getting a lot of @r and other unwanted characters right before I run the query like so:
print_r($query); die; $rows = $wpdb->get_results($query);
SELECT @r:= CASE WHEN value < 60000 THEN 10000 WHEN value >= 60000 AND value < 100000 THEN 20000 WHEN value >= 100000 THEN 100000 END r, (floor((wpp.value) / @r) * @r) minvalue, ((floor((wpp.value + @r) / @r) * @r) - 1) maxvalue, COUNT(*) `count` FROM wp_posts INNER JOIN wp_product wpp ON wpp.post_id = wp_posts.ID AND ( wpp.location IN ('15652') AND (deleted = 0 OR ( deleted = 1 AND ( wpp.value >= 85000 AND wpp.deleteddate >= (DATE_SUB(CURDATE(), INTERVAL 6 MONTH)) ) ) ) ) AND (0 OR (wpp.srp = 1) ) AND ( wpp.isbudget IS NULL OR wpp.isbudget <> 1 ) AND ( wpp.deleted IS NULL OR wpp.deleted <> 1 ) WHERE wp_posts.post_type = 'used-product' AND wpp.value > 0 AND wp_posts.post_status = 'publish' GROUP BY r, minvalue, maxvalue
I want it to output a SQL query that can be run manually. Right now, it can't because of @r:= and @r.
The query is created by appending strings, so the @r= and @r are inside the strings. However, I want to output the SQL query ran by Wordpress.