mattal999 Posted July 26, 2008 Share Posted July 26, 2008 Hi, long time no see everybody. Basically my problem, i want to have all of the artists displayed in a nice little box, but i don't know how to make PHP check for the same artist name when looping through the table. Here is my code: <?php while($song = mysql_fetch_array($query)) { ?> <span class="artist"><center><a href="browsesongs.php?artist=<?php echo $song['artist']; ?>"> <img src="images/art.gif" class="art" width="75" height="75"><br><?php echo $song['artist']; ?></a></center></span> <?php } ?> I have the connect statements and everything, but it displays Linkin Park twice, which i know why it does. How can i do a check to see if Linkin Park comes up again and make sure it doesn't display? Here is the query: <?php $query = mysql_query("SELECT * FROM muzic"); ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/116731-solved-mysql-check-for-same-column-value/ Share on other sites More sharing options...
.josh Posted July 26, 2008 Share Posted July 26, 2008 maybe you should sit down and rethink the whole having it twice in your table in the first place? But anyways, google "mysql distinct" and/or "mysql group by" one or both of those is what you are looking for. Quote Link to comment https://forums.phpfreaks.com/topic/116731-solved-mysql-check-for-same-column-value/#findComment-600219 Share on other sites More sharing options...
DarkWater Posted July 26, 2008 Share Posted July 26, 2008 Can I see your table structure? While you're googling "mysql distinct" and "mysql group by", I'd also suggest googling "database normalization". Quote Link to comment https://forums.phpfreaks.com/topic/116731-solved-mysql-check-for-same-column-value/#findComment-600220 Share on other sites More sharing options...
mattal999 Posted July 26, 2008 Author Share Posted July 26, 2008 heres the exported mysql table structure: CREATE TABLE muzic ( id smallint(10) NOT NULL auto_increment, songname varchar(100) NOT NULL default '', artist varchar(255) NOT NULL default '', mp3 varchar(255) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM; It's the easiest way for me as i don't really want more than 1 table Quote Link to comment https://forums.phpfreaks.com/topic/116731-solved-mysql-check-for-same-column-value/#findComment-600223 Share on other sites More sharing options...
mattal999 Posted July 26, 2008 Author Share Posted July 26, 2008 looks like 'GROUP BY artist' did it for me. Thanks for your help Sneeza Quote Link to comment https://forums.phpfreaks.com/topic/116731-solved-mysql-check-for-same-column-value/#findComment-600228 Share on other sites More sharing options...
DarkWater Posted July 26, 2008 Share Posted July 26, 2008 Why would you not want more than one table? You need more than one table for most relational databases to be used to their fullest. Please explain to me why you wouldn't want one more table. Quote Link to comment https://forums.phpfreaks.com/topic/116731-solved-mysql-check-for-same-column-value/#findComment-600229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.