Solved

How do I select a unique ID number? PHP

Posted on 2011-02-16
7
422 Views
Last Modified: 2012-05-11
On my website it displays a bunch of different users. but when the user is creating an account the query messes up once in a while and inserts the information twice into the database.
So when it displays it, it displays that user twice. Is there a way to weed out duplicates in the SELECT command, when I'm running the query? I tried SELECT DISTINCT but that didn't do it... Right now it looks like this: $query = "SELECT DISTINCT user FROM users";
0
Comment
Question by:anotherdotcommer
7 Comments
 
LVL 16

Expert Comment

by:Chris Harte
Comment Utility
The information has been entered twice into the database. The only difference will be the key index. You will have to go into the database and delete the duplicate.
0
 

Author Comment

by:anotherdotcommer
Comment Utility
I can't go into the database and delete the extras, there are way to many.
So there isn't a way to sort out the duplicates by the username, or another unique row?
0
 
LVL 8

Expert Comment

by:rationalboss
Comment Utility
Run this on mysql :)

CREATE TABLE users2 as
SELECT * FROM users GROUP BY username;

DROP TABLE users;

RENAME TABLE users2 TO users;

Open in new window

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
0
 

Author Comment

by:anotherdotcommer
Comment Utility
I need to do it somehow do it without deleting any of the rows..... Is there any way?
0
 
LVL 8

Accepted Solution

by:
rationalboss earned 500 total points
Comment Utility
If you just want to list the usernames, you can use the following queries:

SELECT DISTINCT(username) FROM users;

-or-

SELECT * FROM users GROUP BY username;
0
 

Author Closing Comment

by:anotherdotcommer
Comment Utility
Thanks!!!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now