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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:27:38+00:00 2026-06-17T14:27:38+00:00

I am creating a simple SQL query in PHP – and for some reason,

  • 0

I am creating a simple SQL query in PHP – and for some reason, even when DISTINCT is used, it shows twice like this:

BC
BC
OH
OH
TX
TX

Here is my code:

<?php
$sql = "SELECT DISTINCT `title`,`extra_fields_search` FROM `blahblah_items` WHERE catid=336 ORDER BY `blahblah_items`.`extra_fields_search` ASC ";
$partnerlisting= mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($partnerlisting))
foreach($row as $cname => $cvalue){
echo '<li>'.substr($row[extra_fields_search], 0, 2).'</li><br>';
}
;

?>

How can I make it so it prints out only one of each?

  • 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-17T14:27:39+00:00Added an answer on June 17, 2026 at 2:27 pm
    SELECT 
        `title`,
        `extra_fields_search` 
    FROM 
        `blahblah_items` 
    WHERE 
        catid=336 
    GROUP BY 
        SUBSTRING(extra_fields_search,1,2) # here. group by first two characters of extra_fields_search
        # or just "GROUP BY extra_fields_search", depends what you need
    ORDER BY 
        `blahblah_items`.`extra_fields_search` ASC
    

    SELECT DISTINCT a,b FROM table works in same way as SELECT a,b FROM table GROUP BY a,b

    Please follow documentation:

    • http://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html
    • http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When creating a simple Flex 4.6 App, where the creationComplete-handler looks like this: protected
This is probably stupid simple, but for some reason I'm having trouble getting it
I'm creating a search function. My sql query uses LIKE and OR LIKE in
I am creating a simple WPF Application with a Sql Connection. The problem is
Was creating a simple console application to do some prototyping and was shocked to
I'm creating a simple file walker to list some files and need to omit
I am having trouble running a simple sql query in Microsoft SQL Server 2005
I am working on creating a SQL query where the result will return a
In some programming contexts getting a scalar value from a sql query is easy:
I'm creating a very simple PHP file that searches a table in my SQLite

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.