We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Remove first 11 characters from SQL query

Development and Programming

Ian Ebden's avatar
Ian Ebden
312 posts
15 years ago
Ian Ebden's avatar Ian Ebden

Anyone able to help me here? My head hurts! I’m querying my Matrix table fine, but need to remove the first 11 characters from my returned data. Obviously just want to remove the chars in my template, not my database. Been Google’ing for a while now with joy. Any help much appreciated!

{exp:query limit="12" paginate="bottom" sql="SELECT 
                row_id, entry_id, row_order, col_id_46, col_id_47, col_id_48 
                FROM exp_matrix_data 
                WHERE col_id_46 !='' 
                ORDER BY entry_id DESC, row_order ASC"
            }
{col_id_46}
{/exp:query}
       
Ingmar's avatar
Ingmar
29,245 posts
15 years ago
Ingmar's avatar Ingmar

The SQL SUBSTRING command should be able to do that:

SELECT SUBSTR(col_id_46, 12), row_id, entry_id, row_order, col_id_47, col_id_48
FROM exp_matrix_data 
WHERE col_id_46 !='' 
ORDER BY entry_id DESC, row_order ASC"

Untested.

       
Ian Ebden's avatar
Ian Ebden
312 posts
15 years ago
Ian Ebden's avatar Ian Ebden

Thanks Ingmar but doesn’t appear to be working. I’ll take a look at the SUBSTR feature though and see if I can figure it out. Thanks.

       
Ingmar's avatar
Ingmar
29,245 posts
15 years ago
Ingmar's avatar Ingmar

Yes, the SUBSTRING command is definitely the way to go. Give that a try.

       
codeM's avatar
codeM
51 posts
15 years ago
codeM's avatar codeM

If you simply want to effect the output and keep the SQl query intact you can use something like (if you PHP enabled for the template on the output stage:

<?php
echo substr("{col_id_46}", 3);
?>
       
codeM's avatar
codeM
51 posts
15 years ago
codeM's avatar codeM

Sorry, made a typo since you want the first 11 you can use :

<?php
echo substr("{col_id_46}", 11);
?>

But please note that that Ingmar’s solution is more effecient if you can correctly get the query mods going, this is just a variation that will uses more processing time.

       
Ian Ebden's avatar
Ian Ebden
312 posts
15 years ago
Ian Ebden's avatar Ian Ebden

Thanks everyone. I’m all sorted now using Ingmar’s approach.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.