kkkaiden Posted October 11, 2009 Share Posted October 11, 2009 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 More sharing options...
Synook Posted October 11, 2009 Share Posted October 11, 2009 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 More sharing options...
PravinBhat Posted October 12, 2009 Share Posted October 12, 2009 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 More sharing options...
PravinBhat Posted October 12, 2009 Share Posted October 12, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.