   SET shippingtotalquantity = @shippingtotalquantity;
   
--  ==========================================================================================================================
--  ==========================================================================================================================
 
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    

    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;      
     --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;      
     --   ---------------------------------------------
     
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
   --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
       --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
        --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
            --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
         --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
             --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
        --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
            --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
         --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
             --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
        --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
            --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
         --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
             --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_SHIPPING_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @shippingstatus, @shippingstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
END  $$
--  --------------------------------------------------------------------------
CREATE PROCEDURE `wp_dragonecommercezyx987_getSlideshowList`(
   IN pagenumber int,
   IN amountperpage int,
   IN myoffset int, 
   IN mysortby varchar(200),
   IN myorder varchar(200),  
   IN searchwords varchar(200),   
   IN searchdescription varchar(200),
   IN slideshowstatus int,
   OUT slideshowtotalquantity int
)
BEGIN
   declare total int default 0;
   declare whereclause varchar(255) default ''; 
   declare orderbyclause varchar(10000) default '';
   
   set @searchwords = CONCAT('%', searchwords, '%');
   set @searchdescription = CONCAT('%', searchdescription, '%');   
   set @amountperpage = amountperpage;
   set @myoffset = myoffset;
   set @slideshowstatus = 0;
   set @slideshowstatus2 = 1;
   if slideshowstatus = -1 then set @slideshowstatus = 0; set @slideshowstatus2 = 1; end if;
   if slideshowstatus = 0 then set @slideshowstatus = 0; set @slideshowstatus2 = 0; end if;
   if slideshowstatus = 1 then set @slideshowstatus = 1; set @slideshowstatus2 = 1; end if;
   
    if searchwords = '' && searchdescription = '' then SET @statement = concat( 'Select count(*) into @slideshowtotalquantity from ', ' wp_dragonecommercezyx987_slideshow WHERE status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @slideshowstatus, @slideshowstatus2;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchdescription = '' then SET @statement = concat( 'Select count(*) into @slideshowtotalquantity from ', ' wp_dragonecommercezyx987_slideshow WHERE name like ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @slideshowstatus, @slideshowstatus2;
       DEALLOCATE PREPARE stmt;
    end if;  
    
    --  -------------------------
        if searchwords = '' && searchdescription != '' then SET @statement = concat( 'Select count(*) into @slideshowtotalquantity from ', ' wp_dragonecommercezyx987_slideshow WHERE description like ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @slideshowstatus, @slideshowstatus2;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchdescription != '' then SET @statement = concat( 'Select count(*) into @slideshowtotalquantity from ', ' wp_dragonecommercezyx987_slideshow WHERE description like ? AND name like ? AND status IN (?,?)' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @slideshowstatus, @slideshowstatus2;
       DEALLOCATE PREPARE stmt;
    end if;  
    
   SET slideshowtotalquantity = @slideshowtotalquantity;
   
--  ==========================================================================================================================
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription = '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE status IN (?,?) order by id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription = '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE name like ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription = '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE status IN (?,?) order by name ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription = '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE name like ? AND status IN (?,?) order by name ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE name like ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription = '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE status IN (?,?) order by id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription = '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE name like ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription = '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE status IN (?,?) order by name DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription = '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE name like ? AND status IN (?,?) order by name DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE name like ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription != '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription != '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND name like ? AND status IN (?,?) order by id ASC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription != '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND status IN (?,?) order by name ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription != '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND name like ? AND status IN (?,?) order by name ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND name like ? AND status IN (?,?) order by createtimeutc ASC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription != '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription != '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND name like ? AND status IN (?,?) order by id DESC LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription != '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND status IN (?,?) order by name DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription != '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND name like ? AND status IN (?,?) order by name DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' then SET @statement = 'SELECT * from wp_dragonecommercezyx987_slideshow WHERE description like ? AND name like ? AND status IN (?,?) order by createtimeutc DESC,id LIMIT ? OFFSET ?'; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @slideshowstatus, @slideshowstatus2, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
END  $$
--  ------------------------------------------------------------------
CREATE PROCEDURE `wp_dragonecommercezyx987_getTaxList`(
   IN pagenumber int,
   IN amountperpage int,
   IN myoffset int, 
   IN mysortby varchar(200),
   IN myorder varchar(200),  
   IN searchwords varchar(200),
   IN searchshownname varchar(200),
   IN searchdescription varchar(200),
   IN fromdate date,
   IN todate date,  
   IN taxstatus int,
   OUT taxtotalquantity int
)
BEGIN
   declare total int default 0;
   declare whereclause varchar(255) default ''; 
   declare orderbyclause varchar(10000) default '';
   
   set @searchwords = CONCAT('%', searchwords, '%');
   set @searchshownname = CONCAT('%', searchshownname, '%');
   set @searchdescription = CONCAT('%', searchdescription, '%');
   
   set @amountperpage = amountperpage;
   set @myoffset = myoffset;
 
   set @fromdate = '1000-01-01 00:00:00';  -- fromdate;
   set @todate = '9999-12-31 23:59:59';  -- todate;
   if fromdate > '1000-01-01 00:00:00' then set @fromdate = fromdate; end if;
   if todate > '1000-01-01 00:00:00' && todate < '9999-12-31 23:59:59' then set @todate = todate; end if; 
   
   set @taxstatus = 0;
   set @taxstatus2 = 1;
   if taxstatus = -1 then set @taxstatus = 0; set @taxstatus2 = 1; end if;
   if taxstatus = 0 then set @taxstatus = 0; set @taxstatus2 = 0; end if;
   if taxstatus = 1 then set @taxstatus = 1; set @taxstatus2 = 1; end if;
   
    if searchwords = '' && searchdescription = '' && searchshownname = '' then SET @statement = concat( "Select count(*) into @taxtotalquantity from ", " wp_dragonecommercezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @taxstatus, @taxstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = concat( "Select count(*) into @taxtotalquantity from ", " wp_dragonecommercezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;
    end if;  
    
    --  -------------------------
    if searchwords = '' && searchdescription != '' && searchshownname = '' then SET @statement = concat( "Select count(*) into @taxtotalquantity from ", " wp_dragonecommercezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = concat( "Select count(*) into @taxtotalquantity from ", " wp_dragonecommercezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;
    end if;  
--  ##########################################################################3

      if searchwords = '' && searchdescription = '' && searchshownname != '' then SET @statement = concat( "Select count(*) into @taxtotalquantity from ", " wp_dragonecommercezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @taxstatus, @taxstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = concat( "Select count(*) into @taxtotalquantity from ", " wp_dragonecommercezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;
    end if;  
    
    --  -------------------------
    if searchwords = '' && searchdescription != '' && searchshownname != '' then SET @statement = concat( "Select count(*) into @taxtotalquantity from ", " wp_dragonecommercezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = concat( "Select count(*) into @taxtotalquantity from ", " wp_dragonecommercezyx987_propertyvalue d WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ? " ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;
    end if;
    
   SET taxtotalquantity = @taxtotalquantity;
   
--  ==========================================================================================================================
--  ==========================================================================================================================
 
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    

    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;      
     --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;      
     --   ---------------------------------------------
     
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
   --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
       --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
        --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
            --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
         --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
             --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname = '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname = '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
        --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
            --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description,d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
         --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
             --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription = '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription = '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id ASC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
        --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
            --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
     --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc ASC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.id DESC LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'name' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'name' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.name DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
     
         --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'shownname' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'shownname' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.shownname DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
             --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.description DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && searchdescription != '' && searchshownname != '' then SET @sqlv = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @searchshownname, @searchdescription, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && searchdescription != '' && searchshownname != '' then SET @statement = "SELECT d.*,fp.name 'fromprovince',fc.name 'fromcountry',tp.name 'toprovince',tc.name 'tocountry' FROM wp_dragonecommercezyx987_propertyvalue d LEFT JOIN wp_dragonecommercezyx987_province fp ON d.fromstateprovinceid = fp.id  LEFT JOIN wp_dragonecommercezyx987_province tp ON d.tostateprovinceid = tp.id LEFT JOIN wp_dragonecommercezyx987_country fc ON d.fromcountryid = fc.id  LEFT JOIN wp_dragonecommercezyx987_country tc ON d.tocountryid = tc.id  WHERE d.propertyid IN (SELECT c.propertyid FROM wp_dragonecommercezyx987_group_property c WHERE c.groupid IN (SELECT b.id FROM wp_dragonecommercezyx987_group b WHERE b.groupcategoryid = (SELECT CAST(a.value AS UNSIGNED) FROM wp_dragonecommercezyx987_setting a WHERE a.name = 'GROUP_CATEGORY_ID_FOR_ORDER_TAX_DETAILS' and a.status = 1 LIMIT 1))) AND  d.shownname LIKE ? AND d.description like ? AND d.name like ? AND d.status IN (?,?) and d.createtimeutc >= ? and d.createtimeutc <= ?  order by d.createtimeutc DESC,d.id LIMIT ? OFFSET ?"; 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchshownname, @searchdescription, @searchwords, @taxstatus, @taxstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
END  $$
--  ------------------------------------------------------------------------------
CREATE PROCEDURE `wp_dragonecommercezyx987_getUserList`(
   IN tablenameprefix varchar(200),
   IN pagenumber int,
   IN amountperpage int,
   IN myoffset int, 
   IN mysortby varchar(200),
   IN myorder varchar(200),  
   IN searchwords varchar(200),  
   IN email varchar(200),
   IN fromdate date,
   IN todate date,   
   IN userstatus int,
   OUT usertotalquantity int
)
BEGIN
   declare total int default 0;
   declare whereclause varchar(255) default ''; 
   declare orderbyclause varchar(10000) default '';
 
   set @tablenameprefix = tablenameprefix;
   if tablenameprefix = '' then set @tablenameprefix = 'wp_'; end if;   
   set @searchwords = CONCAT('%', searchwords, '%');
   set @email = CONCAT('%', email, '%');
   
   set @amountperpage = amountperpage;
   set @myoffset = myoffset;
 
   set @fromdate = '1000-01-01 00:00:00';  -- fromdate;
   set @todate = '9999-12-31 23:59:59';  -- todate;
   if fromdate > '1000-01-01 00:00:00' then set @fromdate = fromdate; end if;
   if todate > '1000-01-01 00:00:00' && todate < '9999-12-31 23:59:59' then set @todate = todate; end if; 
   
   set @userstatus = 0;
   set @userstatus2 = 1;
   if userstatus = -1 then set @userstatus = 0; set @userstatus2 = 1; end if;
   if userstatus = 0 then set @userstatus = 0; set @userstatus2 = 0; end if;
   if userstatus = 1 then set @userstatus = 1; set @userstatus2 = 1; end if;
   
    if searchwords = '' && email = '' then SET @statement = concat( 'Select count(*) into @usertotalquantity from ', ' wp_dragonecommercezyx987_user_status WHERE user_status IN (?,?) and createtimeutc >= ? and createtimeutc <= ?' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userstatus, @userstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && email = '' then SET @statement = concat( 'Select count(*) into @usertotalquantity from ', ' wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ?' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;
    end if;    

    if searchwords = '' && email != '' then SET @statement = concat( 'Select count(*) into @usertotalquantity from ', ' wp_dragonecommercezyx987_user_status  a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_email like ? and a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ?' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @email, @userstatus, @userstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && email != '' then SET @statement = concat( 'Select count(*) into @usertotalquantity from ', ' wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_email like ? and b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ?' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @email, @searchwords, @userstatus, @userstatus2, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;
    end if;   
    
   SET usertotalquantity = @usertotalquantity;
   
--  ==========================================================================================================================   
--  ==========================================================================================================================
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && email = '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by a.userid ASC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && email = '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by a.userid ASC LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'username' && searchwords = '' && email = '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_login ASC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'username' && searchwords != '' && email = '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_login ASC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate,  @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'email' && searchwords = '' && email = '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_email ASC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'email' && searchwords != '' && email = '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_email ASC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;     
    --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && email = '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID  WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_registered ASC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && email = '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_registered ASC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
     if myorder = 'desc' && mysortby = 'id' && searchwords = '' && email = '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by a.userid DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && email = '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by a.userid DESC LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --   ---------------------------------------------
    
   if myorder = 'desc' && mysortby = 'username' && searchwords = '' && email = '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_login DESC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'username' && searchwords != '' && email = '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE a.name like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_login DESC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------
    
   if myorder = 'desc' && mysortby = 'email' && searchwords = '' && email = '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_email DESC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'email' && searchwords != '' && email = '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE a.name like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_email DESC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && email = '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID  WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_registered DESC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && email = '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE a.name like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? order by b.user_registered DESC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    

    --   &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && email != '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by a.userid ASC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != '' && email != '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by a.userid ASC LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'username' && searchwords = '' && email != '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_login ASC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'username' && searchwords != '' && email != '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_login ASC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @email,  @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'email' && searchwords = '' && email != '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_email ASC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'email' && searchwords != '' && email != '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_email ASC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;     
    --   ---------------------------------------------

    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords = '' && email != '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID  WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_registered ASC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'createtimeutc' && searchwords != '' && email != '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_registered ASC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
     if myorder = 'desc' && mysortby = 'id' && searchwords = '' && email != '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by a.userid DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != '' && email != '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE b.user_login like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by a.userid DESC LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    --   ---------------------------------------------
    
   if myorder = 'desc' && mysortby = 'username' && searchwords = '' && email != '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_login DESC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'username' && searchwords != '' && email != '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE a.name like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_login DESC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
     --   ---------------------------------------------
    
   if myorder = 'desc' && mysortby = 'email' && searchwords = '' && email != '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_email DESC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'email' && searchwords != '' && email != '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE a.name like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_email DESC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    --   ---------------------------------------------

    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords = '' && email != '' then SET @sqlv = concat("SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ", @tablenameprefix, "users b on a.userid = b.ID  WHERE a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_registered DESC,a.userid LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'createtimeutc' && searchwords != '' && email != '' then SET @statement = concat('SELECT a.*,b.user_login,b.user_email,b.user_registered from wp_dragonecommercezyx987_user_status a LEFT JOIN ', @tablenameprefix, 'users b on a.userid = b.ID WHERE a.name like ? AND a.user_status IN (?,?) and a.createtimeutc >= ? and a.createtimeutc <= ? and b.user_email LIKE ? order by b.user_registered DESC,a.userid LIMIT ? OFFSET ?'); 
       PREPARE stmt FROM @statement;
       set @searchwords = CONCAT('%', searchwords, '%');
       EXECUTE stmt using @searchwords, @userstatus, @userstatus2, @fromdate, @todate, @email, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;   
    
END  $$
--  ------------------------------------------------------------------------
CREATE PROCEDURE `wp_dragonecommercezyx987_getUserOrderList`(
   IN tablenameprefix varchar(200),
   IN userid int,
   IN pagenumber int,
   IN amountperpage int,
   IN myoffset int, 
   IN mysortby varchar(200),
   IN myorder varchar(200),  
   IN searchwords varchar(200),
   IN searchusername varchar(200), 
   IN minprice DECIMAL(15,2),
   IN maxprice DECIMAL(15,2),
   IN fromdate date,
   IN todate date,
   IN mystatus int,
   OUT ordertotalquantity int
)
BEGIN
   declare total int default 0;
   declare whereclause varchar(255) default ''; 
   declare orderbyclause varchar(10000) default '';

   set @userid = userid;
   set @tablenameprefix = tablenameprefix;
   if tablenameprefix = '' then set @tablenameprefix = 'wp_'; end if;
   
   set @searchwords = CONCAT('%', searchwords, '%');
   set @searchusername = CONCAT('%', searchusername, '%');
   set @amountperpage = amountperpage;
   set @myoffset = myoffset;
   set @minprice = 0;  -- minprice;
   set @maxprice = 9999999999999;  -- maxprice;
   if minprice > 0 then set @minprice = minprice; end if;
   if maxprice > 0 then set @maxprice = maxprice; end if;  

   set @fromdate = '1000-01-01 00:00:00';  -- fromdate;
   set @todate = '9999-12-31 23:59:59';  -- todate;
   if fromdate > '1000-01-01 00:00:00' then set @fromdate = fromdate; end if;
   if todate > '1000-01-01 00:00:00' && todate < '9999-12-31 23:59:59' then set @todate = todate; end if; 

   set @mystatus = -1;
   if mystatus > 0  then set @mystatus = mystatus; end if;

   if searchwords = '' && searchusername = '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername = '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id group by o.id HAVING names LIKE ? ) a" ); 
       PREPARE stmt FROM @statement;       
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
	if searchwords = '' && searchusername != '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ', @tablenameprefix, 'users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername != '' && mystatus <= 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id HAVING names LIKE ?) a" ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --  ---------------------------------------------------------------------------------------
   
    if searchwords = '' && searchusername = '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername = '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id group by o.id HAVING names LIKE ? ) a" ); 
       PREPARE stmt FROM @statement;       
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if;   
    
    
	if searchwords = '' && searchusername != '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', '(Select count(*) from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ', @tablenameprefix, 'users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id) a' ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername;
       DEALLOCATE PREPARE stmt;    
    end if;            
    if searchwords != '' && searchusername != '' && mystatus > 0 then SET @statement = concat( 'Select count(*) into @ordertotalquantity from ', "(Select count(*), group_concat(p.name, '|') 'names' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id HAVING names LIKE ?) a" ); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
   SET ordertotalquantity = @ordertotalquantity;
--  ==========================================================================================================================
--  ==========================================================================================================================
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username'  from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ?  JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id HAVING names like ? ORDER BY o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername = '' && mystatus <= 0   then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername = '' && mystatus <= 0   then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername != '' && mystatus <= 0   then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername != '' && mystatus <= 0   then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------   

    if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
   if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY o.id DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
   
   if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------    
    
    if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus <= 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus <= 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus <= 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  

    --   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    --   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
	if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username'  from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id HAVING names like ? ORDER BY o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;    
    
    if myorder = 'asc' && mysortby = 'id' && searchwords = '' && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'id' && searchwords != ''&& searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername = '' && mystatus > 0   then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername = '' && mystatus > 0   then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
    if myorder = 'asc' && mysortby = 'description' && searchwords = '' && searchusername != '' && mystatus > 0   then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'description' && searchwords != '' && searchusername != '' && mystatus > 0   then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
     --   ---------------------------------------------   

    if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    
   if myorder = 'asc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'asc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;  
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY o.id DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY o.id DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'id' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY o.id DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'id' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY o.id DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------
    
    if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
   
   if myorder = 'desc' && mysortby = 'description' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'description' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY orderdetaildescription DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if; 
    
    --   ---------------------------------------------    
    
    if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername = '' && mystatus > 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id ORDER BY total DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername = '' && mystatus > 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID group by o.id  HAVING names like ? ORDER BY total DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
    
   if myorder = 'desc' && mysortby = 'total' && searchwords = ''  && searchusername != '' && mystatus > 0  then SET @sqlv = concat("Select min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id  JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id ORDER BY total DESC LIMIT ? OFFSET ?");
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
    if myorder = 'desc' && mysortby = 'total' && searchwords != ''  && searchusername != '' && mystatus > 0  then SET @statement = concat("Select  min(o.emailsent) 'emailsent', min(o.ordercancelemailsent) 'ordercancelemailsent', min(o.ordercanceltimeutc) 'ordercanceltimeutc', min(o.ordercancelrefunded) 'ordercancelrefunded', min(o.ordercancelrefundtimeutc) 'ordercancelrefundtimeutc', group_concat(p.name, '|') 'names', o.id, min(o.status) 'status', min(o.totalfee) 'total', min(o.subtotal) 'subtotal', min(o.discountdescriptionforuser) 'discount', min(o.coupondescriptionforuser) 'coupon', min(o.shippingfee) 'shippingfee', min(o.handlingfee) 'handlingfee', min(o.tax) 'tax', min(o.createtimeutc) 'createtimeutc', GROUP_CONCAT(CONCAT('ID: ', p.id, ', Name: ', p.name, ', Price: ', po.unitpriceexcltax, ', Quantity: ', po.quantity, ', Details: ', po.productdescription) SEPARATOR '; ') 'orderdetaildescription', min(u.user_login) 'username' from wp_dragonecommercezyx987_order o JOIN wp_dragonecommercezyx987_product_order po ON o.id=po.orderid and  o.userid = ? AND o.totalfee >= ? and o.totalfee <= ? and o.createtimeutc >= ? and o.createtimeutc <= ? and o.status = ? JOIN wp_dragonecommercezyx987_product p ON po.productid = p.id JOIN ", @tablenameprefix, "users u ON o.userid = u.ID and u.user_login LIKE ? group by o.id  HAVING names like ? ORDER BY total DESC LIMIT ? OFFSET ?"); 
       PREPARE stmt FROM @statement;
       EXECUTE stmt using @userid, @minprice, @maxprice, @fromdate, @todate, @mystatus, @searchusername, @searchwords, @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt;    
    end if;
END  $$

--  -----------------------------------------------------------------
CREATE PROCEDURE `wp_dragonecommercezyx987_getWeightList`(
   IN pagenumber int,
   IN amountperpage int,
   IN myoffset int, 
   IN mysortby varchar(200),
   IN myorder varchar(200), 
   OUT weighttotalquantity int
)
BEGIN
   declare total int default 0;
   declare whereclause varchar(255) default ''; 
   declare orderbyclause varchar(10000) default '';
   
   set @amountperpage = amountperpage;
   set @myoffset = myoffset;
   
    SET @statement = concat( 'Select count(*) into @weighttotalquantity from ', ' wp_dragonecommercezyx987_weight' ); 
	PREPARE stmt FROM @statement;
	EXECUTE stmt;
	DEALLOCATE PREPARE stmt;
         
   SET weighttotalquantity = @weighttotalquantity;
   
--  ==========================================================================================================================
--  ==========================================================================================================================    
    if myorder = 'asc' && mysortby = 'id' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_weight order by id ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    
     --   ---------------------------------------------
	if myorder = 'asc' && mysortby = 'name' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_weight order by name ASC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
    
     --   ---------------------------------------------
    if myorder = 'asc' && mysortby = 'createtimeutc' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_weight order by createtimeutc ASC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;  
    
    --  ===================================================================  BEGIN OF ORDER DESC ========================================
    
    if myorder = 'desc' && mysortby = 'id' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_weight order by id DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
     
    --   ---------------------------------------------
    if myorder = 'desc' && mysortby = 'name' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_weight order by name DESC LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @amountperpage, @myoffset; 
       DEALLOCATE PREPARE stmt2;
    end if;
     
    --   ---------------------------------------------
    if myorder = 'desc' && mysortby = 'createtimeutc' then SET @sqlv = "SELECT * from wp_dragonecommercezyx987_weight order by createtimeutc DESC,id LIMIT ? OFFSET ?";
	   PREPARE stmt2 FROM @sqlv;
	   EXECUTE stmt2 USING @amountperpage, @myoffset;
       DEALLOCATE PREPARE stmt2;
    end if;
END  $$
DELIMITER ;
--  -------------------------------------------
