TinyPortal

Development => Block Codes => Topic started by: fangweile on May 08, 2012, 09:24:36 AM

Title: help in intro display (php) block
Post by: fangweile on May 08, 2012, 09:24:36 AM
global $smcFunc, $scripturl;
$query = $smcFunc['db_query']('', '
    SELECT intro
    FROM {db_prefix}tp_articles
    WHERE useintro = {int:intro}
    AND category = {int:cat}
    ORDER BY rand()
    LIMIT 5',
array('intro' => 1, 'cat' => 4)
);
while ($row = $smcFunc['db_fetch_assoc']($query))
echo htmlspecialchars_decode($row['intro']);


Hello there,

I have used this code above  to display random article intro in a php block but it display some codes in php. I attached the screenshot.

BTW, the articles are written as php article.

Thanks in advance

Title: Re: help in intro display (php) block
Post by: IchBin on May 08, 2012, 10:31:36 PM
What does your intro column contain for those intro's? Is it on all intro's that it displays?
Title: Re: help in intro display (php) block
Post by: fangweile on May 10, 2012, 02:08:18 AM
I used this code to display php intro in my article

echo <<<EOT
<!--Start Intro-->
<center>
<table><tr><td class="images">
<span class="upperframe"><span></span></span>
<div class="roundframe"><div class="blockbody" style="overflow: auto;height: 100%;">
<!--Intro Edit-->
<a href="http://www.allkoreans.net/index.php?page=new-gisaeng-story-korean-drama-2011"><img width="150" src="http://www.allkoreans.net/gallery/albums/Korean-Dramas/New-Gisaeng-Story/thumb_New-Gisaeng-Story-03.jpg" alt="New Gisaeng Story" title="New Gisaeng Story"/>
</a><br/>
<center><strong><a href="http://www.allkoreans.net/index.php?page=new-gisaeng-story-korean-drama-2011">New Gisaeng Story</a></strong></center>
<!--Intro Edit-->
</div></div>
<span class="lowerframe"><span></span></span>
</td></tr>
</table>
</center>
<!--End Intro-->
EOT;
?>


It display just right when viewing the category
http://www.allkoreans.net/index.php?cat=4
But when using it to display in a block is just showed the attached file
Title: Re: help in intro display (php) block
Post by: G6Cad on May 10, 2012, 07:11:26 AM
Remove ?> from the code in the end and test in PHP block, the php tags are not needed in the block as the php block already hold the start and end php tags
Title: Re: help in intro display (php) block
Post by: fangweile on May 10, 2012, 12:17:38 PM
Thank G6 for you reply,

I have remove ?> as you suggested but still it display the same thing.
Title: Re: help in intro display (php) block
Post by: IchBin on May 10, 2012, 05:13:45 PM
There's nothing in the code you posted that indicates it needs to be in a PHP block. It's all HTML so why not use an HTML/javascript block?

Eitherway, you can make it work if you don't use the EOT syntax. Just use a regular echo statement instead.

echo 'all your code goes inbetween the single quotes and ends with a semi-colon';
Title: Re: help in intro display (php) block
Post by: fangweile on May 11, 2012, 02:19:46 AM
This is code I used in php block to display random articles intros.

global $smcFunc, $scripturl;
$query = $smcFunc['db_query']('', '
    SELECT intro
    FROM {db_prefix}tp_articles
    WHERE useintro = {int:intro}
    AND category = {int:cat}
    ORDER BY rand()
    LIMIT 5',
array('intro' => 1, 'cat' => 4)
);
while ($row = $smcFunc['db_fetch_assoc']($query))
echo htmlspecialchars_decode($row['intro']);



And below is the code I used in Article Intro
echo <<<EOT
<!--Start Intro-->
<center>
<table><tr><td class="images">
<span class="upperframe"><span></span></span>
<div class="roundframe"><div class="blockbody" style="overflow: auto;height: 100%;">
<!--Intro Edit-->
<a href="http://www.allkoreans.net/index.php?page=new-gisaeng-story-korean-drama-2011"><img width="150" src="http://www.allkoreans.net/gallery/albums/Korean-Dramas/New-Gisaeng-Story/thumb_New-Gisaeng-Story-03.jpg" alt="New Gisaeng Story" title="New Gisaeng Story"/>
</a><br/>
<center><strong><a href="http://www.allkoreans.net/index.php?page=new-gisaeng-story-korean-drama-2011">New Gisaeng Story</a></strong></center>
<!--Intro Edit-->
</div></div>
<span class="lowerframe"><span></span></span>
</td></tr>
</table>
</center>
<!--End Intro-->
EOT;
?>


I have tried your suggestion
Quote
echo 'all your code goes in between the single quotes and ends with a semi-colon';
and it works however its still display the php tags I used.
take a look at this url
http://www.allkoreans.net/index.php?cat=4
Title: Re: help in intro display (php) block
Post by: IchBin on May 11, 2012, 07:01:12 AM
There's no need for any PHP tags. You only need the echo as I showed you.
Title: Re: help in intro display (php) block
Post by: fangweile on May 11, 2012, 07:58:21 AM
I really can't figure it out.

Title: Re: help in intro display (php) block
Post by: G6Cad on May 11, 2012, 08:00:13 AM
echo '
<!--Start Intro-->
<center>
<table><tr><td class="images">
<span class="upperframe"><span></span></span>
<div class="roundframe"><div class="blockbody" style="overflow: auto;height: 100%;">
<!--Intro Edit-->
<a href="http://www.allkoreans.net/index.php?page=new-gisaeng-story-korean-drama-2011"><img width="150" src="http://www.allkoreans.net/gallery/albums/Korean-Dramas/New-Gisaeng-Story/thumb_New-Gisaeng-Story-03.jpg" alt="New Gisaeng Story" title="New Gisaeng Story"/>
</a><br/>
<center><strong><a href="http://www.allkoreans.net/index.php?page=new-gisaeng-story-korean-drama-2011">New Gisaeng Story</a></strong></center>
<!--Intro Edit-->
</div></div>
<span class="lowerframe"><span></span></span>
</td></tr>
</table>
</center>
<!--End Intro-->';


try this code
Title: Re: help in intro display (php) block
Post by: IchBin on May 11, 2012, 07:01:08 PM
Edited G6's code to show you. There's no need for the EOT stuff.