Page 1 of 1

Help with getting only set number of topics

Posted: Fri Jan 27, 2012 3:18 pm
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.

Re: Help with getting only set number of topics

Posted: Fri Jan 27, 2012 3:20 pm
by Celauran
Add a limit clause to your query.

Code: Select all

$query = "blah blah whatever LIMIT 10";

Re: Help with getting only set number of topics

Posted: Fri Jan 27, 2012 4:16 pm
by Qanyena
don't think blah blah would work I actually don't code much so have no idea what commands would be used.

Re: Help with getting only set number of topics

Posted: Fri Jan 27, 2012 4:42 pm
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";

Re: Help with getting only set number of topics

Posted: Fri Jan 27, 2012 5:39 pm
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.