Quick code formatting question

Discussion forum for MOD Writers regarding MOD Development.
BBRAIN
Registered User
Posts: 55
Joined: Tue Aug 26, 2008 10:33 am

Quick code formatting question

Post by BBRAIN »

Could someone help with the phpbb way to format this code please?

Code: Select all

//$query = "SELECT * FROM phpbb_posts"; 
	 
//$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
	$rawdata = $row['post_text']. " - ". $row['post_id'];
	$dataChunks = explode("[/img", $rawdata); 
	$string_one = "$dataChunks[0][/img]<br />";
	 $stringtwo = $row['post_text']. " - ". $row['post_id'];
	
}

mysql_free_result( $result );
I think it's something like this

Code: Select all

$sqls  = "SELECT * FROM phpbb_posts";

$results1 = $db->sql_query($sqls);

while($list = $db->sql_fetchrow($results1))
  {
	$template->assign_block_vars('data_row', array(

		'RAWDATA'				=> $row['post_text']. " - ". $row['post_id'],
        'DATACHUNKS'			=> explode("[/img", $rawdata),
        'STRINGONE'             => "$dataChunks[0][/img]<br />",
		'STRINGTWO'             => $row['post_text']. " - ". $row['post_id']
		)
	);
  }


$db->sql_freeresult($result1);;
but needs tweeking.

Many Thanks ;)
Sicle
Registered User
Posts: 27
Joined: Fri Aug 06, 2010 8:38 pm
Location: Netherlands, @home
Name: Bart McCall

Re: Quick code formatting question

Post by Sicle »

Like this? :P

Code: Select all

$sqls  = "SELECT * FROM ".$table_prefix."posts";
$results1 = $db->sql_query($sqls);

while($list = $db->sql_fetchrow($results1))
{
    $template->assign_block_vars('data_row', array(
        'RAWDATA'        =>    $row['post_text']. " - ". $row['post_id'],
        'DATACHUNKS'    =>    explode("[/img", $rawdata),
        'STRINGONE'        =>    "$dataChunks[0][/img]<br />",
        'STRINGTWO'        =>    $row['post_text']. " - ". $row['post_id']
    ));
} 

$db->sql_freeresult($result1); 
BBRAIN
Registered User
Posts: 55
Joined: Tue Aug 26, 2008 10:33 am

Re: Quick code formatting question

Post by BBRAIN »

Thanks buddy will try that ;)

EDIT..

Not sure this line is correct

Code: Select all

'STRINGONE'        =>    "$dataChunks[0][/img]<br />",
User avatar
RMcGirr83
Former Team Member
Posts: 21470
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Quick code formatting question

Post by RMcGirr83 »

Code: Select all

    $sqls  = "SELECT * FROM ' . POSTS_TABLE;
    $results1 = $db->sql_query($sqls);

    while($list = $db->sql_fetchrow($results1))
    {
        $template->assign_block_vars('data_row', array(
            'RAWDATA'        =>    $list['post_text']. " - ". $list['post_id'],
            'DATACHUNKS'    =>    explode("[/img", $rawdata), /*$rawdata variable is not assigned will get a debug error*/
            'STRINGONE'        =>    "$dataChunks[0][/img]<br />", /*same as above $dataChunks not defined*/
            'STRINGTWO'        =>    $list['post_text']. " - ". $list['post_id'] //this is the same as RAWDATA above
        ));
    } 

    $db->sql_freeresult($results1);
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
Sicle
Registered User
Posts: 27
Joined: Fri Aug 06, 2010 8:38 pm
Location: Netherlands, @home
Name: Bart McCall

Re: Quick code formatting question

Post by Sicle »

He is right try this:

Code: Select all

$sqls  = "SELECT * FROM " . POSTS_TABLE;
$results1 = $db->sql_query($sqls);

while($list = $db->sql_fetchrow($results1))
{
    //I assume you want this:
    $rawdata=$list['post_text']. " - ". $list['post_id'];
    $dataChunks=explode("[/img", $rawdata);
    
    $template->assign_block_vars('data_row', array(
        'RAWDATA'        =>    $rawdata,
        'DATACHUNKS'    =>    explode("[/img", $rawdata),
        'STRINGONE'        =>    $dataChunks[0]."[/img]<br />",
        'STRINGTWO'        =>   $rawdata
    ));
} 

$db->sql_freeresult($result1);
 
EDIT: I changed $row[''] to $list[''], and some other changes
Last edited by Sicle on Sat Aug 07, 2010 12:06 pm, edited 1 time in total.
BBRAIN
Registered User
Posts: 55
Joined: Tue Aug 26, 2008 10:33 am

Re: Quick code formatting question

Post by BBRAIN »

many thanks but the variables should be like this

Code: Select all

   $rawdata = $row['post_text']. " - ". $row['post_id'];
   $dataChunks = explode("[/img", $rawdata);
   $string_one = "$dataChunks[0][/img]<br />";
    $stringtwo = $row['post_text']. " - ". $row['post_id'];
but don't know how to format it.

trying to explode a post at the image tag

how do i output $string_one, I have the following in html

Code: Select all

			<!-- BEGIN data_row -->	
            		{data_row.STRINGONE}<br />
            <!-- END data_row -->
Thanks for your time ;)
Sicle
Registered User
Posts: 27
Joined: Fri Aug 06, 2010 8:38 pm
Location: Netherlands, @home
Name: Bart McCall

Re: Quick code formatting question

Post by Sicle »

Oke now I get what you want :P try this:

Code: Select all

$sqls  = "SELECT * FROM " . POSTS_TABLE;
$results1 = $db->sql_query($sqls);

while($list = $db->sql_fetchrow($results1))
{
    $rawdata=$list['post_text']. " - ". $list['post_id'];
    $data=explode('[img]',$rawdata);
    $before=$data[0];
    $data=explode('[/img]',$data[1]);
    $after=$data[1];
    $image='[img]'.$data[0].'[/img]';    
    
    $template->assign_block_vars('data_row', array(
        'STRINGONE'        =>    $before,
        'STRINGTWO'        =>    $after,
        'IMAGE'        =>    $image
    ));
} 

$db->sql_freeresult($result1); 
EDIT: changed:

Code: Select all

'IMAGE'        =>    $before
to:

Code: Select all

'IMAGE'        =>    $image
Last edited by Sicle on Sat Aug 07, 2010 12:40 pm, edited 2 times in total.
BBRAIN
Registered User
Posts: 55
Joined: Tue Aug 26, 2008 10:33 am

Re: Quick code formatting question

Post by BBRAIN »

Many Thanks Sicle,

and the html?

as I get nothing displayed.. :D

Suspect it maybe due to bbcode
Sicle
Registered User
Posts: 27
Joined: Fri Aug 06, 2010 8:38 pm
Location: Netherlands, @home
Name: Bart McCall

Re: Quick code formatting question

Post by Sicle »

Code: Select all

<!-- BEGIN data_row -->
    {row_data.STRINGONE}
<!-- END data_row -->
That would show anything before the image.
{row_data.STRINGTWO} Shows everything after the image
BBRAIN
Registered User
Posts: 55
Joined: Tue Aug 26, 2008 10:33 am

Re: Quick code formatting question

Post by BBRAIN »

Thanks for your help m8..

getting

Code: Select all

Parse error: syntax error, unexpected $end
for the html page :(

<!-- BEGIN data_row -->
{data_row.STRINGONE}
<!-- EnD data_row -->

EDIT.. see the issue. Should be

Code: Select all

			<!-- BEGIN data_list -->	
            		{data_list.STRINGONE}
            <!-- END data_list -->
Get no output though :)
Last edited by BBRAIN on Sat Aug 07, 2010 12:41 pm, edited 1 time in total.
Sicle
Registered User
Posts: 27
Joined: Fri Aug 06, 2010 8:38 pm
Location: Netherlands, @home
Name: Bart McCall

Re: Quick code formatting question

Post by Sicle »

Do you get an output when you change:

Code: Select all

'STRINGONE'        =>    $before, 
To:

Code: Select all

'STRINGONE'        =>    $list['post_text']. " - ". $list['post_id'], 
If yes then there probably is nothing before the image.
BBRAIN
Registered User
Posts: 55
Joined: Tue Aug 26, 2008 10:33 am

Re: Quick code formatting question

Post by BBRAIN »

No m8,

entire php page

Code: Select all

<?php


define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);



// phpbb way
 
	
	///////////////////////////////////////////////////////////////////////////
	
	
    $sqls  = "SELECT * FROM " . POSTS_TABLE;
    $results1 = $db->sql_query($sqls);

    while($list = $db->sql_fetchrow($results1))
    {
        $rawdata=$list['post_text']. " - ". $list['post_id'];
        $data=explode('[img]',$rawdata);
        $before=$data[0];
        $data=explode('[/img]',$data[1]);
        $after=$data[1];
        $image='[img]'.$data[0].'[/img]';    
        
        $template->assign_block_vars('data_row', array(
                'STRINGONE'        =>    $list['post_text']. " - ". $list['post_id'], 
            'STRINGTWO'        =>    $after,
            'IMAGE'        =>    $image
        ));
    } 

    $db->sql_freeresult($result1); 
     
?>
BBRAIN
Registered User
Posts: 55
Joined: Tue Aug 26, 2008 10:33 am

Re: Quick code formatting question

Post by BBRAIN »

Should html page be

Code: Select all

						<!-- BEGIN list -->	
            		{data_list.STRINGONE}
            <!-- END list -->
?
Sicle
Registered User
Posts: 27
Joined: Fri Aug 06, 2010 8:38 pm
Location: Netherlands, @home
Name: Bart McCall

Re: Quick code formatting question

Post by Sicle »

No not {list.STRINGONE}, but 1sec ill take a look at the entire page and will edit this post later with the entire page.
BBRAIN
Registered User
Posts: 55
Joined: Tue Aug 26, 2008 10:33 am

Re: Quick code formatting question

Post by BBRAIN »

Many thanks you are a gem :)
Locked

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