smarty (help)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

smarty (help)

Post by spamyboy »

Code: Select all

$sSQL = "SELECT aID,aTitle,aShortDesc,aDate,aHits FROM ".PREFIX."tutorials WHERE aDisplay='Y' ORDER BY aDate DESC LIMIT 5";
$result = $db->query($sSQL);
while (
$row = $result->fetchRow())
{
	$data2[]=$row;
}

$template->assign('data2',$data2);

Code: Select all

<div id="rightColumn">
<div class="rbox">
<div class="rboxtitle">Leatest tutorials </div>
<!--{foreach from=$data2 item="entry"}-->
<div class="rboxother">
<div class="rboxothertitle"><a href="index.php?cmd=tutorial&id={$entry.aID}">{$entry.aTitle}</a></div>
<div class="rboxotherdesc">{$entry.aShortDesc}</div>
</div>
<!--{/foreach}--></div>
So now what I'm trying to do... I can't find find to substr aShortDesc variable.

Here is how do I imagine it:

Code: Select all

$aShortDesc=substr($aShortDesc, 1);
$aShortDesc."...";
But where should I do it ? :|
pleas give example.
User avatar
veridicus
Forum Commoner
Posts: 86
Joined: Fri Feb 23, 2007 9:16 am

Post by veridicus »

The closest thing I know of within smarty is the truncate function

Code: Select all

<div class="rboxotherdesc">{$entry.aShortDesc|truncate:1:""}</div>
That will return the first character of aShortDesc.
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

Could you give me example in this part of code ? Couse I want to do more things with that description over PHP.

Code: Select all

$sSQL = "SELECT aID,aTitle,aShortDesc,aDate,aHits FROM ".PREFIX."tutorials WHERE aDisplay='Y' ORDER BY aDate DESC LIMIT 5";
$result = $db->query($sSQL);
while (
$row = $result->fetchRow())
{
        $data2[]=$row;
}

$template->assign('data2',$data2);
User avatar
veridicus
Forum Commoner
Posts: 86
Joined: Fri Feb 23, 2007 9:16 am

Post by veridicus »

You can alter the data as you get it...

Code: Select all

$sSQL = "SELECT aID,aTitle,aShortDesc,aDate,aHits FROM ".PREFIX."tutorials WHERE aDisplay='Y' ORDER BY aDate DESC LIMIT 5";
$result = $db->query($sSQL);
while (
$row = $result->fetchRow())
{
        $row['aShortDesc'] = substr($row['aShortDesc'], 1);
        $data2[]=$row;
}

$template->assign('data2',$data2);
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

Thanks you so mutch.
Post Reply