Solved

How do I select a unique ID number? PHP

Posted on 2011-02-16
7
424 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
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.
0
 

Author Comment

by:anotherdotcommer
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?
0
 
LVL 8

Expert Comment

by:rationalboss
ID: 34909303
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34910831
0
 

Author Comment

by:anotherdotcommer
ID: 34910907
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
ID: 34912193
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
ID: 34919355
Thanks!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i modify my File download link ? 6 47
Paypal 502 Error 3 67
Should I use subdomains or addon domains? 3 33
Mysql sync between 3-4 mysql db 4 24
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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.

911 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

22 Experts available now in Live!

Get 1:1 Help Now