mysql ek koşullar ile mevcut olmayan sonuçlar elde

0 Cevap php

mysql ve php kullanarak,

I have two tables, I'm french so the table names may sound weird, but I would like to keep them as originals to avoid errors when testing…

"arborescence" (it means categories)
"arborescence_domaine" (it means the subdomains for the categories)

The aim of this system is to be able to have great control
on the subdomains that depends on two things : the category and the zipcode.
Just to explain you before I dive into the problem,
for the same category, let's say "car",
for the zipcode 37000 the subdomain will be "supercars"
but for the zipcode 93000 the subdomain for the same category will be for example "the93supercars"

That's why the "arborescence_domaine" contains the following fields :
id - arborescence_id - DEP - domaine - statut

where "DEP" is the zipcode and "domaine" the subdomain and "statut" is a bool that decides if the subdomain is activated or not.

Şimdi eğlenceli kısmı başlar ...

What I would like to do is do it within 1 single sql query if possible. (otherwise, I know thousands of php methods to achieve the same goal).

What I want now is get all the subdomains from a given array of category and a given zipcode. If the subdomain is not set, it doesn't exist in the "arborescence_domaine" table.

Ama böyle bir sonuç olmasını istiyorsanız:

cat_id domaine DEP
3 vehicule-occasion 37
14 immobilier 37
20 www NULL
26 services-divers 37
28 www NULL
37 www NULL
43 www NULL
3467 www NULL

Bu subdomain ayarlı değilse, bu varsayılan 'www' değerini döndürür anlamına gelir.

Şimdi posta kodu olmadan ben bir faw saat önce bunu öğrendim:

This is a working request (the one that displayed the above array)
SELECT a.id as cat_id, IFNULL(d.domaine, 'www') as domaine, d.DEP
FROM arborescence a
LEFT JOIN arborescence_domaine d on d.arborescence_id=a.id
WHERE a.id in(3,14,20,26,28,37,3467,43);

Ama şimdi posta kodu ile ben beklenen sonuç alamadım:

Aşağıdaki istek:

SELECT a.id as cat_id, IFNULL(d.domaine, 'www') as domaine, d.DEP
FROM arborescence a
LEFT JOIN arborescence_domaine d on d.arborescence_id=a.id
WHERE a.id in(3,14,20,26,28,37,3467,43) AND d.DEP='37';

Aşağıdaki sonucu verir:

cat_id domaine DEP
3 vehicule-occasion 37
14 immobilier 37
26 services-divers 37

Peki, "veritabanı mevcut değil alt etki alanları içinde" gitmişsin.

Now the question is : Is it possible to have a result like the first result shown, but using a zipcode filtering ?

(... Ben aldım, ama sonra yeni bir sorun olarak her zaman ... oluştu düşündüm)

0 Cevap