select statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daebat
Forum Commoner
Posts: 47
Joined: Mon May 11, 2009 10:16 am

select statement

Post by daebat »

I need for the following to only post the first 5 listings and not all of them. How can I modify this to make it work?

Code: Select all

<?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{
 
}
?>
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: select statement

Post by flying_circus »

daebat wrote:I need for the following to only post the first 5 listings and not all of them. How can I modify this to make it work?

Code: Select all

$data = mysql_query("SELECT post_date, post_title, post_status, post_type FROM wp_posts ORDER BY post_date ASC LIMIT 5") or die(mysql_error());
daebat
Forum Commoner
Posts: 47
Joined: Mon May 11, 2009 10:16 am

Re: select statement

Post by daebat »

haha thanks. i JUST found this as soon as you posted. :D
Post Reply