[phpBB Debug] error

Discussion forum for MOD Writers regarding MOD Development.
SCChirp
Registered User
Posts: 23
Joined: Sat Jun 23, 2012 8:54 am

Re: [phpBB Debug] error

Post by SCChirp »

Awesome! Thank you so much. It all works now :)
SCChirp
Registered User
Posts: 23
Joined: Sat Jun 23, 2012 8:54 am

Re: [phpBB Debug] error

Post by SCChirp »

Everything is working fine except for...
When someone posts a reply to one of the topics, it posts that comment as a new topic on the homepage, what could cause this and how can I fix it? Here is my code:

Code: Select all

<?php

$search_limit = 5;

$posts_ary = array(
        'SELECT'    => 'p.*, t.*, u.username, u.user_colour',
    
        'FROM'      => array(
            POSTS_TABLE     => 'p',
        ),
    
        'LEFT_JOIN' => array(
            array(
                'FROM'  => array(USERS_TABLE => 'u'),
                'ON'    => 'u.user_id = p.poster_id'
            ),
            array(
                'FROM'  => array(TOPICS_TABLE => 't'),
                'ON'    => 'p.topic_id = t.topic_id'
            ),
        ),
    
        'WHERE'     => $db->sql_in_set('t.forum_id', array_keys($auth->acl_getf('f_read', true))) . '
                        AND t.topic_status <> ' . ITEM_MOVED . '
                         AND t.topic_approved = 1',
    
        'ORDER_BY'  => 'p.post_id DESC',
    );
    
	$posts = $db->sql_build_query('SELECT', $posts_ary);

	$posts_result = $db->sql_query_limit($posts, $search_limit);

      while( $posts_row = $db->sql_fetchrow($posts_result) )
      {
         $topic_title       = $posts_row['topic_title'];
         $post_author       = get_username_string('full', $posts_row['poster_id'], $posts_row['username'], $posts_row['user_colour']);
         $post_date          = $user->format_date($posts_row['post_time']);
         $post_link       = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p=" . $posts_row['post_id'] . "#p" . $posts_row['post_id']);

         $post_text = nl2br($posts_row['post_text']);

         $bbcode = new bbcode(base64_encode($bbcode_bitfield));         
         $bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);

         $post_text = smiley_text($post_text);
		 
		 echo '<div class="newsbox"><h3><a href=" ' . $post_link . '">' . $topic_title . '</a></h3>';
		 echo '<div class="item"><div class="newsinfo">posted by ' . $post_author . ' on ' . $post_date . '</div>';
		 echo '<p>' . $post_text . '</p>';
		 echo '</div></div>';
      }
	  
	
    $template->set_filenames(array(
        'body' => 'external_body.html'
    ));
	
	$template->display('body');
	

?>
Thank you!
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52126
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: [phpBB Debug] error

Post by Brf »

Yes. That code is designed to show the most recent posts, so it is working properly.
SCChirp
Registered User
Posts: 23
Joined: Sat Jun 23, 2012 8:54 am

Re: [phpBB Debug] error

Post by SCChirp »

How can I limit it to just new posts and not the comments? I want the original post to be displayed, but instead its showing every reply to the original post as a new post also.

Thanks for reply again, Brf :D
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52126
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: [phpBB Debug] error

Post by Brf »

What I would do is change the query from

Code: Select all

        'FROM'      => array(
            POSTS_TABLE     => 'p',
        ),
    
        'LEFT_JOIN' => array(
            array(
                'FROM'  => array(USERS_TABLE => 'u'),
                'ON'    => 'u.user_id = p.poster_id'
            ),
            array(
                'FROM'  => array(TOPICS_TABLE => 't'),
                'ON'    => 'p.topic_id = t.topic_id'
            ),
to

Code: Select all

        'FROM'      => array(
            TOPICS_TABLE     => 't',
        ),
    
        'LEFT_JOIN' => array(
            array(
                'FROM'  => array(USERS_TABLE => 'u'),
                'ON'    => 'u.user_id = p.poster_id'
            ),
            array(
                'FROM'  => array(POSTS_TABLE => 'p'),
                'ON'    => 'p.post_id = t.topic_first_post_id'
            ),
User avatar
RMcGirr83
Former Team Member
Posts: 21586
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: [phpBB Debug] error

Post by RMcGirr83 »

Don't forget to change the order by ;)
Appreciate the extensions/mods/support then buy me a beerImage
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52126
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: [phpBB Debug] error

Post by Brf »

MySQL should be smart enough to figger it out.... but yes, you can change

Code: Select all

 'ORDER_BY'  => 'p.post_id DESC',
to

Code: Select all

 'ORDER_BY'  => 't.topic_first_post_id DESC',
SCChirp
Registered User
Posts: 23
Joined: Sat Jun 23, 2012 8:54 am

Re: [phpBB Debug] error

Post by SCChirp »

Hey again!

I made the changes but now I'm getting this error:
General Error
SQL ERROR [ mysqli ]

Unknown column 'p.poster_id' in 'on clause' [1054]

SQL

SELECT p.*, t.*, u.username, u.user_colour FROM (phpbb_topics t) LEFT JOIN phpbb_users u ON (u.user_id = p.poster_id) LEFT JOIN phpbb_posts p ON (p.post_id = t.topic_first_post_id) WHERE t.forum_id IN (1, 2, 6, 8, 9, 10, 13, 14, 16, 17, 18, 19, 20) AND t.topic_status <> 2 AND t.topic_approved = 1 ORDER BY p.post_id DESC LIMIT 5

BACKTRACE

FILE: [ROOT]/includes/db/mysqli.php
LINE: 182
CALL: dbal->sql_error()

FILE: [ROOT]/includes/db/mysqli.php
LINE: 224
CALL: dbal_mysqli->sql_query()

FILE: [ROOT]/includes/db/dbal.php
LINE: 170
CALL: dbal_mysqli->_sql_query_limit()

FILE: /home/content/72/7095572/html/tts-demo/newsfeed.php
LINE: 32
CALL: dbal->sql_query_limit()

FILE: /home/content/72/7095572/html/tts-demo/index.php
LINE: 69
CALL: include('/home/content/72/7095572/html/tts-demo/newsfeed.php')
Do I need to edit any of this code, that comes after the query?

Code: Select all

$posts = $db->sql_build_query('SELECT', $posts_ary);

	$posts_result = $db->sql_query_limit($posts, $search_limit);

      while( $posts_row = $db->sql_fetchrow($posts_result) )
      {
         $topic_title       = $posts_row['topic_title'];
         $post_author       = get_username_string('full', $posts_row['poster_id'], $posts_row['username'], $posts_row['user_colour']);
         $post_date          = $user->format_date($posts_row['post_time']);
         $post_link       = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p=" . $posts_row['post_id'] . "#p" . $posts_row['post_id']);

         $post_text = nl2br($posts_row['post_text']);

         $bbcode = new bbcode(base64_encode($bbcode_bitfield));         
         $bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);

         $post_text = smiley_text($post_text);
What does this mean?
Thanks again everyone!
SCChirp
Registered User
Posts: 23
Joined: Sat Jun 23, 2012 8:54 am

Re: [phpBB Debug] error

Post by SCChirp »

To clarify, on my forum board I have a Category called "News". I have a Forum inside of that called "News Updates". I want only the topics from "News Updates" to be shown on the web-site. I do not want any of the comments on those updates to be shown though.

"News" is the first top or first category that I have.
"News Updates" is the first forum in the "News" Category.
(Not sure if this information is helpful to know.)

Everything else is coming along smooth, have been able to reskin and modify the forum, I just can't understand the code used to display topics on external page!

Thanks agian,
Chirp

EDIT:
I tried using this article to modify my query, but kept running into errors =/
http://blog.phpbb.com/2009/11/09/how-to ... nal-pages/
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52126
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: [phpBB Debug] error

Post by Brf »

SCChirp wrote:

Code: Select all

Unknown column 'p.poster_id' in 'on clause' [1054]
Replace p.poster_id with t.topic_poster
SCChirp
Registered User
Posts: 23
Joined: Sat Jun 23, 2012 8:54 am

Re: [phpBB Debug] error

Post by SCChirp »

Hey Brf,
When I try that, I get this error:
Parse error: syntax error, unexpected ';', expecting ')' in /home/content/72/7095572/html/newsfeed.php on line 27
Line 27 contains this code:

Code: Select all

);
I tried changing it to "));", and ";", but neither works.
User avatar
Saldash
Registered User
Posts: 619
Joined: Mon Nov 10, 2008 8:08 am
Location: Flintshire, UK
Name: Stuart Jackson
Contact:

Re: [phpBB Debug] error

Post by Saldash »

Can you post a few line before and after that one please?
Just so we can see what that line is meant to be part of.
World Recoded UK - DreamHost Site of the Month winner February 2011!
SCChirp
Registered User
Posts: 23
Joined: Sat Jun 23, 2012 8:54 am

Re: [phpBB Debug] error

Post by SCChirp »

Sure!
Here is the block of code leading up to the line in question. The last line is "line 27" from the previous post I made.

Code: Select all

   'FROM'      => array(
            TOPICS_TABLE     => 't',
        ),
    
        'LEFT_JOIN' => array(
            array(
                'FROM'  => array(USERS_TABLE => 'u'),
                'ON'    => 'u.user_id = p.poster_id'
            ),
            array(
                'FROM'  => array(POSTS_TABLE => 'p'),
                'ON'    => 'p.post_id = t.topic_first_post_id'
            ),
That is the code suggested by Brf. I tried using that instead of:

Code: Select all

   'FROM'      => array(
            POSTS_TABLE     => 'p',
        ),
    
        'LEFT_JOIN' => array(
            array(
                'FROM'  => array(USERS_TABLE => 'u'),
                'ON'    => 'u.user_id = p.poster_id'
            ),
            array(
                'FROM'  => array(TOPICS_TABLE => 't'),
                'ON'    => 'p.topic_id = t.topic_id'
            ),
When I make the change I get the error that I mentioned above. I'm basically just trying to get topics(not posts) from a particular forum to my external homepage. The code I'm using currently displays all topics AND posts(replies, etc) made on ALL of the forum, instead of from just from one category.

Thanks for your time!
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52126
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: [phpBB Debug] error

Post by Brf »

So where is the ";" mentioned in the error?
There is no semi-colon in the code you are posting.
SCChirp
Registered User
Posts: 23
Joined: Sat Jun 23, 2012 8:54 am

Re: [phpBB Debug] error

Post by SCChirp »

Hey Brf... Sorry, here is the code again. The last line is line 27 and contains the ";".

Code: Select all

$posts_ary = array(
        'SELECT'    => 'p.*, t.*, u.username, u.user_colour',
    
      'FROM'      => array(
            TOPICS_TABLE     => 't',
        ),
    
        'LEFT_JOIN' => array(
            array(
                'FROM'  => array(USERS_TABLE => 'u'),
                'ON'    => 'u.user_id = p.poster_id'
            ),
            array(
                'FROM'  => array(POSTS_TABLE => 'p'),
                'ON'    => 'p.post_id = t.topic_first_post_id'
            ),
    
        'WHERE'     => $db->sql_in_set('t.forum_id', array_keys($auth->acl_getf('f_read', true))) . '
                        AND t.topic_status <> ' . ITEM_MOVED . '
                         AND t.topic_approved = 1',
    
        'ORDER_BY'  => 'p.post_id DESC',
    );
If I just remove it I get this error:
Parse error: syntax error, unexpected T_VARIABLE, expecting ')' in /home/content/72/7095572/html/newsfeed.php on line 29
And here is line 29:

Code: Select all

$posts = $db->sql_build_query('SELECT', $posts_ary);
Thanks again :)
Locked

Return to “[3.0.x] MOD Writers Discussion”