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

  • SEARCH
  • Home
  • 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 8887917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:55:29+00:00 2026-06-14T21:55:29+00:00

I have a database table where I am storing all the values from an

  • 0

I have a database table where I am storing all the values from an external xml file. Since my project requirement demands me to deal with this unnormalized data. I need to help to extract data in an appropriate way.

I have two web pages (one for categories) and one for products.My database table looks like this:

**product_id       Code        Name                   ProductRange         ProductSubRange         WebCategory**

   1               1002        Lid 30l                  Crystal;Uni         LIDs                    Household products

   2               10433       Casa Basket Silver       Casa                Casa Hipster BASKET      Kitchenware

   3               17443       Casa Basket Ice White    Casa;Laundry         LAUNDRY BASKET         Laundry products

   4               13443       Garden tub               Eden                Eden Garden Pots        Household products

   5               199990       Black Lid 201          Crystal             Crystal Lids            Household products

The product that belong to more than one productRange is indicated my semicolon(;). For example,above product_id 1 with name “Lid 301” belongs to two Product Ranges “Crystal” and “Uni”. Same is for product_id 3. However product 2 belongs to single ProductRange.

MY QUESTIONs:

1) How can I construct a query so that it could return “ProductRange” based on my query_string values of “Webcategory”? For example:
if I get “Household Products” as my WebCategory from query string, it could give me distinct like this:

      Household Products
                       |-Crystal
                       |-Uni 
                       |-Eden

      Laundry Products
                       |-Casa
                       |-Laundry 

            Kitchenware
                       |-Casa

2) Based on extracted ProductRanges, I want to display products separately in my webpages according to the product range and webcategory. For example, if I choose “Crystal” from above, it could give me Products with product_id “1” and “5” respectively like this:

  Household Products|
                    |-Crystal
                             |-Lid 301 (product_id=1)
                             |-Balck Lid 201 (product_id=5)

                    |-Uni
                             |-Lid 301 (product_id=1)

                    |-Eden
                             |-Garden Tub


         Kitchenware|
                    |-Casa
                          |-Casa Basket silver


    Laundry Products|
                    |-Casa
                            |-Casa Basket Ice White
                    |  
                    |-Laundry
                            |-Casa Basket Ice White

Can anyone guide me how can I retrieve records from the database and what I will need to do as I am new to programming? I would appreciate if anyone could help me in this regard.

  • 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-06-14T21:55:30+00:00Added an answer on June 14, 2026 at 9:55 pm

    In order to get distinct product ranges based on a give WebCategory input = ‘XYZ’, you can use the following – don’t be intimidated by the numberstable, it’s just a helpful table that contains rows each with increasing integer values from 1 … up to N where N is the maximum number of characters in your ProductRange column. These can be made by hand or using a special insert/select query like the one found here:
    http://www.experts-exchange.com/Database/MySQL/A_3573-A-MySQL-Tidbit-Quick-Numbers-Table-Generation.html

    SELECT DISTINCT  
    SUBSTRING(ProductRange FROM number FOR LOCATE(';', ProductRange, number) - number) AS ProductRange  
    FROM (  
        SELECT ProductRange, CASE number WHEN 1 THEN 1 ELSE number + 1 END number  
        FROM (  
            SELECT mydatabasetable.ProductRange, numberstable.number  
            FROM mydatabasetable  
            INNER JOIN numberstable  
            ON numberstable.number >= 1  
            AND numberstable.number <= CHAR_LENGTH(mydatabasetable.ProductRange)  
            WHERE WebCategory = 'XYZ'  
        ) TT  
        WHERE number = 1 OR (number + 1) <= CHAR_LENGTH(ProductRange)  
    ) TT  
    WHERE SUBSTRING(ProductRange FROM number FOR 1) = ';'  
    OR numberstable.number = 1;  
    

    In order to retrieve a result set with all values WebCategory, ProductRange and Product for your website you can use the below slightly modified version derived from the above query. So that the results will appear more meaningful at first, I added an ORDER BY clause to keep all same-category, same-product-range products in sequence one after the other. This might or might not be desired as you might prefer to do that in your application/server-script code. In that case you can remove the ORDER BY clause without doing any harm.

    SELECT WebCategory,  
    SUBSTRING(  
        ProductRange  
        FROM number  
        FOR LOCATE(';', ProductRange, number) - number  
    ) AS ProductRange,  
    Product  
    FROM (  
        SELECT WebCategory, ProductRange, Product,  
        CASE number  
        WHEN 1 THEN 1  
        ELSE number + 1  
        END number  
        FROM (  
            SELECT WebCategory, ProductRange, Product, numberstable.number  
            FROM mydatabasetable  
            INNER JOIN numberstable  
            ON numberstable.number >= 1  
            AND numberstable.number <= CHAR_LENGTH(ProductRange)  
        ) TT  
        WHERE number = 1 OR (number + 1) <= CHAR_LENGTH(ProductRange)  
    ) TT  
    WHERE SUBSTRING(ProductRange FROM number FOR 1) = ';'  
    OR numberstable.number = 1  
    ORDER BY WebCategory, ProductRange, Product  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function of mine which selects all room types from the database,
I want to get two field values from a database table and combine them
Within a project I have a database table with the following columns I would
i have database table like this +-------+--------------+----------+ | id | ip | date |
that my problem: I have database table like that: id (AI) market_id 1 6
I have a database table with some rows that I want to fetch using
I have a database table containing dates (`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00').
I have a database table, my goal is to read in each of the
I have a database table named Categories . I want to create a form
I have one database table which contains 8 columns. One of the columns is

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.