Jump to content

Select One Id From Db When There Is More Than One


kkkaiden
 Share

Recommended Posts

In my database I have an id repeating about 12 times but I only want it to show up once when I use this code

<?phpinclude'connect.php';mysql_select_db("$dbname");$query  = "SELECT id FROM user";$result = mysql_query($query) or die(mysql_error());while($row = mysql_fetch_array($result, MYSQL_ASSOC)){	echo "{$row['id']}";} ?>

Help please?

Link to comment
Share on other sites

Umm, an ID is supposed to be unique, so you can use it for identification (e.g. as a PRIMARY KEY). If, for whatever reason, your ID isn't unique, you should have another arbitrary indexed column for that purpose.But anyway, you can use SELECT DISTINCT.

SELECT DISTINCT id FROM user

Edited by Synook
Link to comment
Share on other sites

Hello Just Change it To---------<?phpinclude'connect.php';mysql_select_db("$dbname");$query = "SELECT id FROM user";$result = mysql_query($query) or die(mysql_error());//Use if instead of while belowif($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "{$row['id']}";}?>Hello if you have entered the same id 12 times it will display 12 times......

Edited by PravinBhat
Link to comment
Share on other sites

Hello Just Change it To---------<?phpinclude'connect.php';mysql_select_db("$dbname");$query = "SELECT id FROM user";$result = mysql_query($query) or die(mysql_error());//Use if instead of while belowif($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "{$row['id']}";}?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...