Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2010
    Posts
    7

    Unanswered: How to limit the number of outputs

    This script gets blog posts from a database, but it doesnt limit the amount if gets, it can fill up a whole page and clutter things up
    PHP Code:
    function GetBlogPosts($inId=null$inTagId =null)
    {
        if (!empty(
    $inId))
        {
            
    $query mysql_query("SELECT * FROM blog_posts WHERE id = " $inId " ORDER BY id DESC"); 
        }
        else if (!empty(
    $inTagId))
        {
            
    $query mysql_query("SELECT blog_posts.* FROM blog_post_tags LEFT JOIN (blog_posts) ON (blog_post_tags.postID = blog_posts.id) WHERE blog_post_tags.tagID =" $tagID " ORDER BY blog_posts.id DESC");
        }
        else
        {
            
    $query mysql_query("SELECT * FROM blog_posts ORDER BY id DESC");
        }
        
        
    $postArray = array();
        while (
    $row mysql_fetch_assoc($query))
        {
            
    $myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['postfull'], $row["author_id"], $row['date_posted']);
            
    array_push($postArray$myPost);
        }
        return 
    $postArray;
    }
    ?> 
    i would like that to only output/show a specific amount of blog posts but i dont know how

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    look at the MySQL limit clause
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Oct 2010
    Posts
    7
    Thanks alot!

  4. #4
    Join Date
    Jul 2010
    Posts
    7
    Different database system has different syntax to limit the number of outputs. you can check it out: SQL select top

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by sqlfan View Post
    Different database system has different syntax to limit the number of outputs.
    that is correct, but of very limited relevance in this forum


    Quote Originally Posted by sqlfan View Post
    you can check it out: SQL select top
    please, don't do that

    TOP does not work in mysql
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Jul 2010
    Posts
    7
    Quote Originally Posted by r937 View Post
    that is correct, but of very limited relevance in this forum


    please, don't do that

    TOP does not work in mysql
    Actually, the link I posted above talks about the different ways to limit the results among SQL server, mySQL and Oracle.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •