Help with getting only set number of topics

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
Qanyena
Forum Newbie
Posts: 3
Joined: Fri Jan 27, 2012 3:14 pm

Help with getting only set number of topics

Post by Qanyena »

I have a file that gets news articles from a table. I am trying to figure out how to make it only select a set number of topic/articles

Code: Select all

$news_fora_id = array('2'); // Change in the fora id's you need
$query = "
    SELECT p.topic_id, p.forum_id, p.post_time, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid,
        u.user_id, u.user_email, u.username, u.user_posts, u.user_rank, u.user_colour, u.user_allow_viewonline, u.user_allow_viewemail,
            (
                SELECT COUNT( post_id )
                FROM " . POSTS_TABLE . "
                    WHERE topic_id = p.topic_id
            ) AS aantal_posts
    FROM " . POSTS_TABLE . " AS p, " . USERS_TABLE . " AS u
        WHERE " . $db->sql_in_set( 'p.forum_id', 3) . "
            AND u.user_id = p.poster_id
    GROUP BY topic_id
    ORDER BY topic_id DESC
";
//die('<pre>' . $query );
$result = $db->sql_query( $query );
$recruit_sql = "SELECT * FROM evo_recruit WHERE `ID`='1'";
$recruit_result = mysql_query($recruit_sql);
$rect = mysql_fetch_array($recruit_result);
if ($rect[Status] == 'Open')
if the entire file is needed please let me know but that is the selection code.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Help with getting only set number of topics

Post by Celauran »

Add a limit clause to your query.

Code: Select all

$query = "blah blah whatever LIMIT 10";
Qanyena
Forum Newbie
Posts: 3
Joined: Fri Jan 27, 2012 3:14 pm

Re: Help with getting only set number of topics

Post by Qanyena »

don't think blah blah would work I actually don't code much so have no idea what commands would be used.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Help with getting only set number of topics

Post by Celauran »

You're really going to make me copy/paste the query from your code above?

Code: Select all

$query = "
    SELECT p.topic_id, p.forum_id, p.post_time, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid,
        u.user_id, u.user_email, u.username, u.user_posts, u.user_rank, u.user_colour, u.user_allow_viewonline, u.user_allow_viewemail,
            (
                SELECT COUNT( post_id )
                FROM " . POSTS_TABLE . "
                    WHERE topic_id = p.topic_id
            ) AS aantal_posts
    FROM " . POSTS_TABLE . " AS p, " . USERS_TABLE . " AS u
        WHERE " . $db->sql_in_set( 'p.forum_id', 3) . "
            AND u.user_id = p.poster_id
    GROUP BY topic_id
    ORDER BY topic_id DESC
    LIMIT 10";
Qanyena
Forum Newbie
Posts: 3
Joined: Fri Jan 27, 2012 3:14 pm

Re: Help with getting only set number of topics

Post by Qanyena »

Thank you. Sorry I said I didn't know how to write it. Saying add LIMIT 10 to the end of the quary would of worked too :)

LOL oops just looked and you did sorry bud am pretty tired atm been trying to fix a dozen things at once.
Post Reply