$sd = 1;
    }
}
$txtSearch = $_POST["txtSearch"];
if ($txtSearch != '') {
    //$where.=" AND (p.product_name REGEXP ('".mysql_real_escape_string($txtSearch).".*$') || p.product_description REGEXP ('".mysql_real_escape_string($txtSearch).".*$')  )";
    $where .= " AND (CONCAT(p.product_name, p.product_description) REGEXP ('" . mysql_real_escape_string($txtSearch) . ".*\$'))";
}
if ($chkProductArtist == "1") {
    $where = '';
    $where .= " AND (CONCAT(s.artist_name,s.first_name, s.last_name) REGEXP ('" . mysql_real_escape_string($txtSearch) . ".*\$'))";
    //$where .= '  AND  (s.artist_name LIKE "%'.mysql_real_escape_string($txtSearch).'%" || s.first_name LIKE "%'.mysql_real_escape_string($txtSearch).'%" || s.last_name LIKE "%'.mysql_real_escape_string($txtSearch).'%" ||  s.company LIKE "%'.mysql_real_escape_string($txtSearch).'%" ) ';
}
/*-------Multicart 2.0 Upgradation starts------*/
if ($ddlCategory == 'made-to-order') {
    $categorylist = implode(",", getCategoryDescendants(2));
    $where .= " AND p.eMadetoOrder='Y' ";
}
if (isNotNull($categorylist)) {
    $where .= " AND p.product_category IN ({$categorylist}) ";
}
/*-------Multicart 2.0 Upgradation ends------*/
$sortBy = $_REQUEST['txtPriceSort'];
$sql = "SELECT DISTINCT p.vapproved, p.product_id,po.product_option_id,(p.product_price+po.additional_price) AS product_price,po.image_small,po.product_stock,po.discount,p.eMadetoOrder,\n         p.product_name,s.artist_name,p.eMadetoOrder,\n         (SELECT pm.vimage_name FROM " . $tableprefix . "product_view_images pm where pm.nimage_productid=p.product_id LIMIT 0,1)AS smallimage\n            FROM " . $tableprefix . "products p\n            INNER JOIN " . $tableprefix . "product_options po ON po.product_id = p.product_id AND po.default_option = 'YES'\n            INNER JOIN " . $tableprefix . "artists s ON p.product_artist_id  = s.artist_id\n            INNER JOIN " . $tableprefix . "categories c ON c.category_id  = p.product_category\n            WHERE p.deleted = 'N' AND p.vapproved='Y'\n            AND s.vapproved='Y' AND s.deleted = 'N' AND s.plan_expired='N' AND s.vacationmode = 'N' \n            AND  po.product_stock > 0 AND c.vEnable='Y' ";
if (getSettingsValue('product_listing_fee') > 0) {
    $sql .= " AND p.payment_status='COMPLETED' ";
}
$sql = $sql . $where;
$ddlSelectedCategory = str_replace("'", "", stripslashes($ddlCategory));
if (!isset($pagenum)) {
    $pagenum = 1;
function getCategoryDescendants($catid)
{
    global $tableprefix;
    static $option_results;
    static $i = 0;
    $option_results[$i] = $catid;
    $i++;
    /*---Mulicart 2.0 Upgradation-------*/
    $sql = "SELECT category_id FROM `" . $tableprefix . "categories` where parent_id = " . $catid;
    $result = mysql_query($sql) or die(mysql_error());
    /*---Mulicart 2.0 Upgradation-------*/
    if (mysql_num_rows($result) != 0) {
        while ($row = mysql_fetch_array($result)) {
            getCategoryDescendants($row["category_id"]);
        }
    }
    return $option_results;
}