If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to limit the number of outputs

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-27-10, 22:13
thm120 thm120 is offline
Registered User
 
Join Date: Oct 2010
Posts: 7
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
Reply With Quote
  #2 (permalink)  
Old 10-28-10, 03:27
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
look at the MySQL limit clause
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 10-28-10, 10:56
thm120 thm120 is offline
Registered User
 
Join Date: Oct 2010
Posts: 7
Thanks alot!
Reply With Quote
  #4 (permalink)  
Old 11-02-10, 10:34
sqlfan sqlfan is offline
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old 11-02-10, 10:41
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 11-03-10, 15:13
sqlfan sqlfan is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On