mysql mevcut olmayan sonuçlar elde

0 Cevap php

Using php and mysql,
I have a table "subdomains" that contains subdomains for my application, depending of a category. subdomains - id, cat_id, subdomain

Some categories have subdomain and others don't have. For those that don't have subdomain, I want the subdomain to be 'www'.

Şimdi, benim alt etki alanları tabloda birkaç değerler arasında, örneğin, şunlardır:

subdomains : id, cat_id, subdomain
             1,  6,   "sales"
             2,  7,   "infos"

Şimdi, örnek $ aCatIds = array (1,5,6,8) için cat_id bir dizi var;

Mysql sorgunun sonunda ben böyle bir şey istiyorum:

array(
0 => (cat_id="1", subdomain="www") ,
1 => (cat_id="5", subdomain="www") ,
2 => (cat_id="6", subdomain="sales") ,
3 => (cat_id="8", subdomain="www") ,
)

O bir mysql sorgu sadece mümkün mü?

Ben php kullanmak ve bu gibi şeyler denedim:

$stmt = "select cat_id, ifnull('www', subdomain) as subdomain
    from subdomains
    where cat_id in (". implode(',', $aCatIds) .")";

Ama ben sadece (yukarıdaki örnekte 6) ayarlanan değerleri almak, ve ben beklenen dizisini almak için mysql nasıl söyleyeceğimi bilmiyorum.

0 Cevap