Page 1 of 1

select statement

Posted: Fri Feb 19, 2010 2:12 pm
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{
 
}
?>

Re: select statement

Posted: Fri Feb 19, 2010 2:18 pm
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());

Re: select statement

Posted: Fri Feb 19, 2010 2:23 pm
by daebat
haha thanks. i JUST found this as soon as you posted. :D