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
What does your intro column contain for those intro's? Is it on all intro's that it displays?
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
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
Thank G6 for you reply,
I have remove ?> as you suggested but still it display the same thing.
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';
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
There's no need for any PHP tags. You only need the echo as I showed you.
I really can't figure it out.
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
Edited G6's code to show you. There's no need for the EOT stuff.