Jess McKenzie
Jess McKenzie

Reputation: 8385

Getting data if one value is NULL

I am having an issue with the code below and my issue is the following:

I need to be able to select the shop_shipping_rule_region_code if the country_iso is NULL but I also need to get the $country_iso data as well if present

What I am after:

The Final Result will have:

Overnight UPS
NZ Snail Mail
Whole World (in this example)

DB:

`shop_shipping_rules` (`shop_shipping_rule_id`, `shop_shipping_rule_country_iso`, `shop_shipping_rule_region_code`, `shop_shipping_rule_name`, 
    `shop_shipping_rule_type_single`, `shop_shipping_rule_item_single`, `shop_shipping_rule_type_multi`, 
    `shop_shipping_rule_item_multiple`,`shop_shipping_rule_created`, `shop_shipping_rule_modified`, `website_id`)
     VALUES
    (41, 'NZ', 'ALL', 'Overnight UPS', 'single', 2.00, 'multi', 4.00, '2013-11-05 02:30:19', '2013-11-05 03:00:27', 64),
    (44, 'NZ', NULL, 'NZ Snail Mail', 'single', 25.00, 'multi', 35.00, '2013-11-14 03:57:06', NULL, 64),
    (45, NULL, 'ALL', 'Whole World', 'single', 90.00, 'multi', 150.00, '2013-11-14 05:05:53', NULL, 64),
    (46, NULL, 'EU', 'EU Ship', 'single', 28.00, 'multi', 35.00, '2013-11-15 01:04:01', NULL, 64);

Upvotes: 1

Views: 81

Answers (1)

MiguelAngel_LV
MiguelAngel_LV

Reputation: 1258

if (isset($country_iso))
   $sql = "SELECT * FROM shop_shipping_rules WHERE country_iso IS NULL OR country_iso = '$country_iso' ";
else
    $sql = "SELECT * FROM shop_shipping_rules WHERE country_iso IS NULL";

Upvotes: 1

Related Questions