Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5527

mpa4hu on "MySQL question"

$
0
0

Didn't knew where to post so dicided this forum.

I have wp e-commerce installed and tring to remake some global search plugin so it works with my shop.
Everything works perfect so far, just adding Price FROM-TO filter.
form works great (I guess) but something is wrong with my SQL query I think.

I added LEFT JOIN postmeta (where posts have prices) and I have $min_price and $max_price variables (which echos fine in php)

Here is my code

$request = $wpdb->prepare( "SELECT ".$wpdb->base_prefix."v_posts.*
    				FROM ".$wpdb->base_prefix."v_posts
    				LEFT JOIN ".$wpdb->users."
    				ON ".$wpdb->users.".ID=".$wpdb->base_prefix."v_posts.post_author
    				LEFT JOIN ".$wpdb->base_prefix."v_postmeta
    				ON ".$wpdb->base_prefix."v_posts.ID=".$wpdb->base_prefix."v_postmeta.post_id
    					AND ".$wpdb->base_prefix."v_postmeta.meta_key='_wpsc_special_price'
    				WHERE ".$wheresearch." ".$termsearch."
    				AND ( post_status = 'publish' OR post_status = 'private' )
    		      	AND ".$post_type."
    		      	AND ".$min_price." < ".$wpdb->base_prefix."v_postmeta.meta_value
    		      	AND ".$max_price." > ".$wpdb->base_prefix."v_postmeta.meta_value
    		      	ORDER BY ".$wpdb->base_prefix."v_posts.blog_id ASC, ".$wpdb->base_prefix."v_posts.post_date DESC, ".$wpdb->base_prefix."v_posts.comment_count DESC" );

When I query it behaves very strange, It displays things but not exactly by MIN/MAX price. I don't get the pattern yet.

any help?


Viewing all articles
Browse latest Browse all 5527

Trending Articles