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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:05:22+00:00 2026-05-17T17:05:22+00:00

Using PHP and MySQL I’m trying to select unique values from multiple columns in

  • 0

Using PHP and MySQL I’m trying to select unique values from multiple columns in a table (but not all the columns in the table) and put all the unique values from each column selected in its own array. The uniqueness of each columns values should be compared only to other values in the same column.

The code below puts all the unique values from all the columns in the $make_array then puts empty values in all the rest of the arrays.

How can I select only unique values from these columns and put each columns values in its own array?

$sql = "
    (SELECT make FROM items)
    UNION
    (SELECT model FROM items)
    UNION
    (SELECT year FROM items)
    UNION
    (SELECT month FROM items)
    UNION
    (SELECT day FROM items)
    UNION
    (SELECT hour FROM items)";

$result = @mysql_query($sql, $con) or die(mysql_error());

while($row = mysql_fetch_array($result)) {

    $make = $row[make];
    $model = $row[model];
    $year = $row[year];
    $month = $row[month];
    $day = $row[day];
    $hour = $row[hour];

    $make_array[make][] = $make;
    $model_array[model][] = $model;
    $year_array[year][] = $year;
    $month_array[month][] = $month;
    $day_array[day][] = $day;
    $hour_array[hour][] = $hour;
}
  • 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-17T17:05:23+00:00Added an answer on May 17, 2026 at 5:05 pm

    If you want to keep it as one SQL statement, then you could:

    $sql = "
        SELECT DISTINCT 'make' as descr,make as val FROM items
        UNION
        SELECT DISTINCT 'model' as descr,model as val FROM items
        UNION
        SELECT DISTINCT 'year' as descr,year as val FROM items
        UNION
        SELECT DISTINCT 'month' as descr,month as val FROM items
        UNION
        SELECT DISTINCT 'day' as descr,day as val FROM items
        UNION
        SELECT DISTINCT 'hour' as descr,hour as val FROM items";
    
    $result = @mysql_query($sql, $con) or die(mysql_error());
    
    while($row = mysql_fetch_array($result)) {
        $make_array[$row['descr']][]=$row['val'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP and MySQL I'm trying to get all the distinct values out the
I am using php / mysql and protype.js to delete record from a table.
Using PHP and MySQL, I have a forum system I'm trying to build. What
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
Ok here is the situation (using PHP/MySQL) you are getting results from a large
Using PHP / MySQL all encoded up as UTF, we have recently had to
i am writing a site from scratch using php/mysql and am using GET requests
I am using PHP/MySQL to handle the image uploading. I want all images that
I'm using PHP/MySQL and I've always used DATETIME to store created and updated values,

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.