php - mysql get non existing results -


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

There are subdomains in some categories and others do not have it. Those who do not have a subdomain, I want to be a subdomain 'www'.

Now there are some values ​​in my subdomain table, for example:

  Now, I have an array of cat_id, for example $ aCatIds = array (1, 1, 2, 2, 2) 5,6,8);  

I want something like this at the end of the mysql query:

  array (0 = & gt; (cat_id = "1", subdomain = "www"), 1 = & Gt; (cat_id = "5", subdomain = "www"), 2 = & gt; (cat_ id = "6", subdomain = "sale"), 3 =>  
< P> Is it possible only with a mysql query?

I use php and tried things like this:

  $ stmt = "sub - Select the cat_id, ifnull ('www', subdomain) in the form of subdomain from domains where in cat_id ("Implode (',', $ aCatIds).");  

But only those values Which is set (6 in the example given above), and I do not know how to get mysql to expect the array.

To make this work, you must include the existing data (left) (where cat_id is present). For example, if I consider the cat table , Which is in the cat_id context, then it will:

 select  c.id as Cat_id, IFNULL (s.subdomain, 'www') to cat C LEFT Join subdomain ON s.cat_id = c.id WHERE c.id IN (1,2,3) , 4);  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -