dizzyvapor Posted August 13, 2007 Share Posted August 13, 2007 I'm still pretty new at PHP so I'm sorry if this is a simple question. On the homepage of my site I am trying to display the titles of my most recent wordpress blogs. However, I don't want it to show more than one result with the same value. I just want it to show the first result with that value. Here is my code: <?php $query = "SELECT * FROM wp_posts ORDER BY id desc LIMIT 0, 5"; $result = mysql_query( $query, $connect ); while( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ){ ?> <ul> <li><a href="<?php echo 'http://www.blog.mysiteurl.com/?p='.$row['ID']; ?>"><?php echo $row['post_title']; ?></a></li> <?php } mysql_close( $connect ); ?> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/64705-solved-removing-multiple-values/ Share on other sites More sharing options...
frost Posted August 13, 2007 Share Posted August 13, 2007 $query = "SELECT * FROM wp_posts ORDER BY id desc LIMIT 0, 5"; That grabs the first 5 results starting at 0 Change it to $query = "SELECT * FROM wp_posts ORDER BY id desc LIMIT 1"; Quote Link to comment https://forums.phpfreaks.com/topic/64705-solved-removing-multiple-values/#findComment-322652 Share on other sites More sharing options...
dbo Posted August 13, 2007 Share Posted August 13, 2007 I'd also suggest you don't use SELECT * otherwise if your datamodel changes your code has to change and this isn't acceptable. List out the fields which you wish to pull out. Quote Link to comment https://forums.phpfreaks.com/topic/64705-solved-removing-multiple-values/#findComment-322657 Share on other sites More sharing options...
dizzyvapor Posted August 13, 2007 Author Share Posted August 13, 2007 $query = "SELECT * FROM wp_posts ORDER BY id desc LIMIT 0, 5"; That grabs the first 5 results starting at 0 Change it to $query = "SELECT * FROM wp_posts ORDER BY id desc LIMIT 1"; That's not what I'm looking for. I want duplicate values from the database not to show. For instance if there is more than one post title with the value of "hello", I just want the first "hello" to show up. Quote Link to comment https://forums.phpfreaks.com/topic/64705-solved-removing-multiple-values/#findComment-322662 Share on other sites More sharing options...
dbo Posted August 13, 2007 Share Posted August 13, 2007 $query = "SELECT DISTINCT title FROM wp_posts ORDER BY id DESC LIMIT 0, 5"; Replacing the title field with the actual field. Quote Link to comment https://forums.phpfreaks.com/topic/64705-solved-removing-multiple-values/#findComment-322668 Share on other sites More sharing options...
frost Posted August 13, 2007 Share Posted August 13, 2007 I see, you want 5 results but only distinct titles? try: $query = "SELECT distinct ID,post_title FROM wp_posts ORDER BY id desc LIMIT 0, 5"; Quote Link to comment https://forums.phpfreaks.com/topic/64705-solved-removing-multiple-values/#findComment-322673 Share on other sites More sharing options...
dizzyvapor Posted August 13, 2007 Author Share Posted August 13, 2007 Thanks! That worked! Quote Link to comment https://forums.phpfreaks.com/topic/64705-solved-removing-multiple-values/#findComment-322683 Share on other sites More sharing options...
dbo Posted August 13, 2007 Share Posted August 13, 2007 Mark us solved mark us solved! Quote Link to comment https://forums.phpfreaks.com/topic/64705-solved-removing-multiple-values/#findComment-322687 Share on other sites More sharing options...
dizzyvapor Posted August 13, 2007 Author Share Posted August 13, 2007 Hmm, it's not linking up to the posts anymore. I will continue to investigate that on my own but that's a good start. Quote Link to comment https://forums.phpfreaks.com/topic/64705-solved-removing-multiple-values/#findComment-322688 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.