Jump to content

Select One Id From Db When There Is More Than One


kkkaiden

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

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......

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...