Echo always printing at top?

Discussion forum for MOD Writers regarding MOD Development.
Locked
ht3k
Registered User
Posts: 8
Joined: Tue Oct 13, 2009 4:40 am

Echo always printing at top?

Post by ht3k »

Hello everyone, I'm having an issue with some custom code I want to run on PHPBB.

It's more of a question than anything technical. I have a loop running that retrieves information from the database. I want to display them like a result page with all the information.


Now as far as I know I have everything configured right. I have added a function to the custom page browse.php as follows:

Code: Select all

$template->assign_vars(array(
	'AMPBROWSE'     => ampbrowse()
);
along with {AMPBROWSE} in:

Code: Select all

$template->set_filenames(array(
    'body' => 'browse.html',
));
And I have a function that looks something like this in browse.php

Code: Select all

function ampbrowse(){

................

while ($row = mysql_fetch_array($sl_result, MYSQL_BOTH)){
		return "$row[0]"

}
The problem is I can see the FIRST entry with return (where it's supposed to be). It just won't loop afterwards. I'm still fairly new so I'm not sure if return should be functioning like that.

If I change that the "RETURN" with an ECHO EVERYTHING appears like all the information from the database that I want to display. But it does not do it in the <div> that I put for the function to show somewhere in the middle of browse.html template. It appears at the VERY top of the page, above the forum, banner and everything else. I've looked everywhere and I can't seem to find a solution. Can someone explain what I can do or what I could possibly be doing wrong?
ht3k
Registered User
Posts: 8
Joined: Tue Oct 13, 2009 4:40 am

Re: Echo always printing at top?

Post by ht3k »

Wow I'm an idiot, I could have sworn I put this under the support forums. Mods, could you move this please? I apologize but I haven't gotten any sleep trying to figure this out. Hehe. :lol:
User avatar
carlino1994
Registered User
Posts: 102
Joined: Mon Feb 16, 2009 5:50 pm
Location: Italy
Name: Carlo
Contact:

Re: Echo always printing at top?

Post by carlino1994 »

Read this page of phpBB.com wiki.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52137
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Echo always printing at top?

Post by Brf »

A function call can only return once. Once you hit the "return" statement, the function is terminated.

Probably what you want to do is setup a $template->assign_block_vars() inside that function, or have it return an array and loop on the array in the main.
User avatar
carlino1994
Registered User
Posts: 102
Joined: Mon Feb 16, 2009 5:50 pm
Location: Italy
Name: Carlo
Contact:

Re: Echo always printing at top?

Post by carlino1994 »

If you would do as Brf say, this is an example:

Code: Select all

while($row = $db->sql_fetchrow($result)) {
    $template->assign_block_vars('block_name', array(
        'FIELD_1'    => $row['field_1'],
        'FIELD_2'    => $row['field_2']
    ));
}
This is the example for the template:

Code: Select all

<!-- BEGIN block_name -->Field 1: {block_name.FIELD_1} - Field 2: {block_name.FIELD_2}<!-- END block_name -->
comkidwizzer3
Registered User
Posts: 375
Joined: Fri Jul 13, 2007 8:24 am
Location: $user->data['user_location'];
Contact:

Re: Echo always printing at top?

Post by comkidwizzer3 »

Also I don't think anyone has noticed but

Code: Select all

$template->assign_vars(array(
   'AMPBROWSE'     => ampbrowse()
); 
It is missing a close parenthesis ;)

Just saying ;)
~My MODs~
Login After Register - v1.0.0 | Custom Ranks MOD - RC

~!Hasher!~
Locked

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