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 8611769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:27:22+00:00 2026-06-12T04:27:22+00:00

This is my data id cost cat foreign colours ——————————————————– 385_white 99 swarovski 12

  • 0

This is my data

id          cost    cat         foreign     colours
--------------------------------------------------------   
385_white   99      swarovski   12          black;blue
386_white   99      swarovski   12          black;blue;green
387_white   99      swarovski   12          yellow;green
389_white   99      swarovski   12          white;silver
385_white   99      swarovski   12          silver

This is my query

$checkSQL=mysql_query("SELECT * FROM `products`");
while($r = mysql_fetch_assoc($checkSQL)) {

    echo '<ul class="ColourList">';
    $cols = explode( ';', $r['colours'] );
    foreach ( $cols as $col ){
        echo '<li class="' . $col . '">' . $col . '</li>';
    }
    echo '</ul>';
}

This basically returns a list of colors for each record

<ul>
 <li>black</li>
 <li>blue</li>
</ul>

However I want to return a single list, for every color i the entire database and alphabetize it. So basically get all the colors, in all rows, split them in a list in ABC order but without them repeating – is this possible with my clients setup? Just need some direction? Thinking explode with replace and then us the ORDER BY ASC command?

  • 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-12T04:27:23+00:00Added an answer on June 12, 2026 at 4:27 am

    This is a nice example of what happens if you not normalize your database. At first it seems easy, but ones runs into trouble later.

    Change your tables like this:

    Products:

    id          cost    cat         foreign     
    --------------------------------------------   
    385_white   99      swarovski   12     
    

    ProductColors:

    id          color_id     
    ----------------------
    385_white   1                
    385_white   2
    

    Colors:

    id          name     
    ----------------------
    1           Black     
    2           Blue
    

    If you have a structure like this, it is very easy ro query the database for what you want.

    Example:

    To query all available colors:

    select * from colors
    

    To query all available colors for 385_white:

    select * from productcolors where id = '385_white'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my data id cost cat foreign colours -------------------------------------------------------- 385_white 99 swarovski 12
This data is for a holiday cottage's simple accommodation calendars. The data is simple
I have this data in cell A1: Majestic Properties Design District, LLC, Ste. 101,
If user insert this data 16 HOUSEHOLD STAND FAN AA070021A the output should be
I need to make this data variable global: $.ajax({ url: get_data.php, cache: false, dataType:
i Want to fetch this data using json decode. Please Help.. So far i
i have this data | car_name | year | price | Honda | 2011
I am accessing this data from a web server using NSURL, what I am
I have this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
I have this data: /blabla/blabla (abs,def) /yxz I use this regex (.*)(?:\(([^$]*)\))?\n But it

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.