Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 980139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:19:57+00:00 2026-05-16T04:19:57+00:00

Using php and mysql, I have a table subdomains that contains subdomains for my

  • 0

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’.

Now in my subdomains table there are a few values, for example :

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

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

At the end of the mysql query I would like a something like this :

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") ,
)

Is it possible with only one mysql query ?

I use php and tried things like this :

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

But I only get the values that are set (6 in the above example), and I don’t know how to tell mysql to get the expected array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:19:57+00:00Added an answer on May 16, 2026 at 4:19 am

    To make this work, you’ll have to (left) join to existing data (where the cat_id does exist). For instance, if I assume a cat table exists which the cat_id references, ‘t would be so:

    SELECT c.id as cat_id,IFNULL(s.subdomain,'www')
    FROM cat c 
    LEFT JOIN subdomains s
    ON s.cat_id = c.id
    WHERE c.id IN (1,2,3,4);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using mysql and php, I have two tables, I'm french so the table names
I'm using PHP and MySQL and I have a table with 3 fields ((
hello i have some problems with my php ajax script i'm using PHP/mysql i
using php and mysql I have two tables, a users table and a profiles
I am using php/mysql, and have a database table with image url. I would
i am using php/mysql. i have a product table . in which most product
I have two timestamps recorded on a mysql table using php. How can I
I have a MySQL table that contains many rows. The table structure is as
Using PHP, I am building an application that is MySQL database resource heavy, but
Using PHP and MySQL, I have a forum system I'm trying to build. What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.