Jamroom Logo Jamroom 5 Core
is now Open Source!
User Support Forum Archive (Read Only)
Jamroom Developers:
How to truncate array results for jmSelect?
musiccreatures



Joined: 20 Jun 2009
Posts: 344
Location: Portland Oregon

Posted: 09/09/09 00:49 
Assuming that tbl_title is a varchar(100) and using the below code, how would I truncate the {$_tmp['tbl_title']} to 30 characters or less? I tried {$tmp['tbl_title']|truncate:30} but I received a Parse error: syntax error, unexpected '|', expecting '}'. Any idea's what I did wrong?

Code

            foreach ($_rt as $_tmp) {
                $_sel["{$_tmp['tbl_id']}"] = "{$_tmp['tbl_title']} ({$_mcad['tbl_startdate']})";
            }


Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 09/09/09 01:21 
You can only use smarty in templates, so you will need to use php

Code
           foreach ($_rt as $_tmp) {
                $truncatedtitle = substr($_tmp['tbl_title'], 0, 30);
                $_sel["{$_tmp['tbl_id']}"] = $truncatedtitle . " ({$_mcad['tbl_startdate']})";
            }


http://uk.php.net/substr


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
musiccreatures



Joined: 20 Jun 2009
Posts: 344
Location: Portland Oregon

Posted: 09/09/09 08:51 
Awesome. Thanks SteveX

Back to top
Brian
Jamroom Team


Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA

Posted: 09/10/09 10:34 
Just an FYI that if you know you are going to always truncate, it's faster to do it in PHP - i.e.


Code

foreach ($_rt as $_tmp) {
    $_sel["{$_tmp['tbl_id']}"] = substr("{$_tmp['tbl_title']} ({$_mcad['tbl_startdate']})",0,30);
}


Hope this helps!

- Brian


_________________
Make sure and check out:
* The Jamroom FAQ
* The Jamroom Documentation
Back to top
musiccreatures



Joined: 20 Jun 2009
Posts: 344
Location: Portland Oregon

Posted: 09/10/09 21:00 
Thanks for the reply bigguy. I am fairly new to PHP, but very experienced in classic ASP(the dead technology). lol. But im catching on quick Very Happy

Back to top
Display posts from previous:   
User Support Forum Archive (Read Only)
Jamroom Developers

 
Solutions
• Social Media Platform
• Social Networking Software
• Musician Website Manager
• Community Builder
Products
• Jamroom Core
• Jamroom Addons
• Jamroom Modules
• Jamroom Marketplace
Support
• Support Forum
• Documentation
• Support Center
• Contact Support
Community
• Community Forum
• Member Sites
• Developers
Company
• About Us
• Contact Us
• Privacy Policy
©2003 - 2010 Talldude Networks, LLC.