Go Premium for a chance to win a PS4. Enter to Win


How do I select a unique ID number? PHP

Posted on 2011-02-16
Medium Priority
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";
Question by:anotherdotcommer
LVL 17

Expert Comment

by:Chris Harte
ID: 34908992
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.

Author Comment

ID: 34909015
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?

Expert Comment

ID: 34909303
Run this on mysql :)

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


RENAME TABLE users2 TO users;

Open in new window

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34910831

Author Comment

ID: 34910907
I need to do it somehow do it without deleting any of the rows..... Is there any way?

Accepted Solution

rationalboss earned 2000 total points
ID: 34912193
If you just want to list the usernames, you can use the following queries:

SELECT DISTINCT(username) FROM users;


SELECT * FROM users GROUP BY username;

Author Closing Comment

ID: 34919355

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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 …
Suggested Courses

916 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