Page 1 of 2

Quick code formatting question

Posted: Sat Aug 07, 2010 9:20 am
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 ;)

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 11:41 am
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); 

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 11:51 am
by BBRAIN
Thanks buddy will try that ;)

EDIT..

Not sure this line is correct

Code: Select all

'STRINGONE'        =>    "$dataChunks[0][/img]<br />",

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 11:57 am
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);

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 12:03 pm
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

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 12:05 pm
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 ;)

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 12:11 pm
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

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 12:14 pm
by BBRAIN
Many Thanks Sicle,

and the html?

as I get nothing displayed.. :D

Suspect it maybe due to bbcode

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 12:17 pm
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

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 12:22 pm
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 :)

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 12:39 pm
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.

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 12:43 pm
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); 
     
?>

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 12:46 pm
by BBRAIN
Should html page be

Code: Select all

						<!-- BEGIN list -->	
            		{data_list.STRINGONE}
            <!-- END list -->
?

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 12:48 pm
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.

Re: Quick code formatting question

Posted: Sat Aug 07, 2010 12:49 pm
by BBRAIN
Many thanks you are a gem :)