View Single Post
  #25  
Old September 15th, 2012, 05:11 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Try this function:
PHP Code:
function dfr_get_brands($cat=false) {
    global 
$wpdb;
    if (
$cat) { $cat_query "WHERE p2c.cat_id = ".$cat." "; }
    
$brands $wpdb->get_results("    
        SELECT brand, p2c.cat_id
        FROM "
.$wpdb->prefix."dfr_shop_products AS p
        INNER JOIN "
.$wpdb->prefix."dfr_shop_p2c AS p2c ON p.id = p2c.id
        
$cat_query
        GROUP BY brand
    "
);
    
$html '<option value="">Select a brand</option>';
    foreach (
$brands as $brands) {
        if (
trim($brands->brand) != "") {
            
$selected = (strip_tags(stripslashes($_GET['brand']))==$brands->brand) ? ' selected="selected"' '';
            
$html .= '<option value="'.$brands->brand.'"'.$selected.'>'.$brands->brand.'</option>';
        }
    }
    return 
$html;