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
spamyboy
Forum Contributor
Posts: 266 Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius
Post
by spamyboy » Tue Mar 13, 2007 12:34 pm
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.
veridicus
Forum Commoner
Posts: 86 Joined: Fri Feb 23, 2007 9:16 am
Post
by veridicus » Tue Mar 13, 2007 12:46 pm
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.
spamyboy
Forum Contributor
Posts: 266 Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius
Post
by spamyboy » Tue Mar 13, 2007 12:52 pm
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);
veridicus
Forum Commoner
Posts: 86 Joined: Fri Feb 23, 2007 9:16 am
Post
by veridicus » Tue Mar 13, 2007 1:00 pm
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);
spamyboy
Forum Contributor
Posts: 266 Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius
Post
by spamyboy » Tue Mar 13, 2007 1:05 pm
Thanks you so mutch.