daebat Posted February 19, 2010 Share Posted February 19, 2010 I'm trying to pull the latest blog posts from a blog but only the latest 5. What do I need to modify from this snippet: $data = mysql_query("SELECT post_date, post_title FROM wp_posts ORDER BY post_date ASC") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/192659-select-statement/ Share on other sites More sharing options...
daebat Posted February 19, 2010 Author Share Posted February 19, 2010 I've modified it a little bit so you all can get what I'm trying for: <?php $data = mysql_query("SELECT post_date, post_title, post_status, post_type FROM wp_posts ORDER BY post_date ASC ") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) if($info['post_status'] == 'publish'){ if($info['post_type'] == 'post'){ echo"<li>".$info['post_title'] . "</li>"; } else{ } } else{ } ?> This lists all of the posts but I need only the latest 5. Quote Link to comment https://forums.phpfreaks.com/topic/192659-select-statement/#findComment-1014971 Share on other sites More sharing options...
daebat Posted February 19, 2010 Author Share Posted February 19, 2010 figured it out... THANKS PHP FREAKS! YOU"RE SO HELPFUL! Quote Link to comment https://forums.phpfreaks.com/topic/192659-select-statement/#findComment-1014990 Share on other sites More sharing options...
shlumph Posted February 19, 2010 Share Posted February 19, 2010 Just so people know the answer, you'll want to limit your query: SELECT post_date, post_title FROM wp_posts ORDER BY post_date ASC LIMIT 5 Quote Link to comment https://forums.phpfreaks.com/topic/192659-select-statement/#findComment-1015000 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.