knaj11 Posted April 21, 2010 Share Posted April 21, 2010 my goal is to query artist name from db which that is starting with a certian first letter sample if L, queries lady gaga, lady antebellum and etc...each artist name contains different songs. lady gaga has bad romance, pokerface, and etc... now my problem is that it my query repeats lady gaga since it has two songs... considering my db table has id, artist, title, content sample db datas: 1 lady gaga bad romance content 2 lady gaga poker face content 3 lady antebellum idk content my query would result lady gaga lady gaga lady antebellum having a hard time to adjust this one to not query repeating artist... $query = "select id, artist from lyrics where artist like 'a%' order by artist ASC"; $result = mysql_query($query) or die ("Error in query: $query . " . mysql_query()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $id = $row['id']; $artist = $row['artist']; ?> <li><b><a href="content.php?id=<?php echo $id; ?> "><?php echo $artist . ' lyrics'; ?></a></b><br> <?php } } else { echo 'No Content'; } thanks in advance for helping... Quote Link to comment https://forums.phpfreaks.com/topic/199227-query-help/ Share on other sites More sharing options...
grim1208 Posted April 21, 2010 Share Posted April 21, 2010 shooting from the help try googling mysql DISTINCT see if that helps you any Quote Link to comment https://forums.phpfreaks.com/topic/199227-query-help/#findComment-1045602 Share on other sites More sharing options...
knaj11 Posted April 23, 2010 Author Share Posted April 23, 2010 problem with distinct here is that im selecting the id and artist in the db table... see code above...id here is auto increment. Quote Link to comment https://forums.phpfreaks.com/topic/199227-query-help/#findComment-1046880 Share on other sites More sharing options...
fenway Posted April 23, 2010 Share Posted April 23, 2010 problem with distinct here is that im selecting the id and artist in the db table... see code above...id here is auto increment. That makes no sense -- if you have two artists repeated, that's due to having 2 sets of lyrics -- that's not WRONG. Quote Link to comment https://forums.phpfreaks.com/topic/199227-query-help/#findComment-1047068 Share on other sites More sharing options...
knaj11 Posted April 26, 2010 Author Share Posted April 26, 2010 exactly..2 set of lyrics under 1 artist...i want my query to not display repeating artist. Quote Link to comment https://forums.phpfreaks.com/topic/199227-query-help/#findComment-1048343 Share on other sites More sharing options...
cags Posted April 26, 2010 Share Posted April 26, 2010 Think about what your asking for, only one row to be returned per artist, but you want the id per matched row, this isn't possible. As fenway mentioned the results you are getting are correct. You simply need to filter it when outputting it with PHP. $cur_artist = ''; while( $row = mysql_fetch_assoc( $result ) ) { if( $cur_artist != $row['artist'] ) { $cur_artist = $row['artist']; echo $cur_artist . '<br/>'; } echo $row['id']; } Quote Link to comment https://forums.phpfreaks.com/topic/199227-query-help/#findComment-1048439 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.