ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

[OPEN] Query-module / SQL question

December 09, 2010 9:44am

Subscribe [3]
  • #1 / Dec 09, 2010 9:44am

    Digitaal Dier

    75 posts

    Hi guys,

    I’ve implemented an alphabetical listing according to one of the methods in the Wiki, but apparently there’s also entries that start with a number. I thought retooling the query would be a walk in the park, but I can’t seem to get it to work, on account of being a total SQL-noob.

    My code is:

    {exp:query sql="SELECT title, entry_id, url_title AS urlt FROM exp_channel_titles WHERE channel_id = '4' AND title LIKE '[0-9]%' ORDER BY title ASC"}
                                    <li><a href="/dev.php/artists/detail/{urlt}">{title}</a></li>
                                    {/exp:query}

    I’ve tried hardcoding numbers into the LIKE-statement which works, so I probably just don’t have the right syntax for this.. Any thoughts?

    Thanks!

  • #2 / Dec 09, 2010 2:07pm

    James Smith

    259 posts

    I’m no expert either but instead of LIKE ‘[0-9]%’, try

    REGEXP '^[0-9]'
  • #3 / Dec 09, 2010 5:12pm

    michaelroling

    34 posts

    REGEXP is the best way as mentioned above.  The only other way I can think of would be to substring the title and then perform a numeric comparison.  This will cause MySQL to cast the string as an integer.

    AND (substr(title,1,1) >=0 AND substr(title,1,1) <=9)

    or you could do

    AND substr(title,1,1) BETWEEN 0 and 9
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases