Professional Web Applications Themes

exploding strings - MySQL

In a moment or two I'm going to have a table that looks a bit like this: id hyphenated 1 [all-bar-one] 2 [black-and-white] 3 [black-and-blue] 4 [all-for-one]   all and bar black blue for one white Is there a simple way of doing this without resorting to PHP?...

  1. #1

    Default exploding strings

    In a moment or two I'm going to have a table that looks a bit like
    this:
    id hyphenated
    1 [all-bar-one]
    2 [black-and-white]
    3 [black-and-blue]
    4 [all-for-one]
     

    all
    and
    bar
    black
    blue
    for
    one
    white

    Is there a simple way of doing this without resorting to PHP?

    strawberry Guest

  2. #2

    Default Re: exploding strings

    strawberry wrote: 
    >
    > all
    > and
    > bar
    > black
    > blue
    > for
    > one
    > white
    >
    > Is there a simple way of doing this without resorting to PHP?
    >[/ref]
    are the brackets part of the data?

    --
    lark -- net
    To reply to me directly, delete "despam".
    lark Guest

  3. #3

    Default Re: exploding strings

    On 18 May, 19:20, lark <net> wrote: 
    > [/ref]


    >
    > are the brackets part of the data?
    >
    > --
    > lark -- net
    > To reply to me directly, delete "despam".[/ref]


    Yes - but disregarding the brackets is the easy part!

    strawberry Guest

  4. #4

    Default Re: exploding strings

    strawberry wrote: 
    >> are the brackets part of the data?
    >>
    >> --
    >> lark -- net
    >> To reply to me directly, delete "despam".[/ref]
    >
    >
    > Yes - but disregarding the brackets is the easy part!
    >[/ref]


    try this:

    select distinct SUBSTRING_INDEX(hyphenated,'-', 1) as col1 from t1
    union
    select distinct substring_index(substring(hyphenated,
    instr(substring_index(hyphenated, '-', 2), '-')+1),'-',1) as col1 from t1
    union
    select distinct SUBSTRING_INDEX(hyphenated,'-',-1) as col1 from t1
    order by col1



    hyphenated is the name of column in t1 table.
    --
    lark -- net
    To reply to me directly, delete "despam".
    lark Guest

  5. #5

    Default Re: exploding strings

    On May 18, 7:52 pm, lark <net> wrote: [/ref]
    > [/ref]

    >
    > try this:
    >
    > select distinct SUBSTRING_INDEX(hyphenated,'-', 1) as col1 from t1
    > union
    > select distinct substring_index(substring(hyphenated,
    > instr(substring_index(hyphenated, '-', 2), '-')+1),'-',1) as col1 from t1
    > union
    > select distinct SUBSTRING_INDEX(hyphenated,'-',-1) as col1 from t1
    > order by col1
    >
    > hyphenated is the name of column in t1 table.
    > --
    > lark -- net
    > To reply to me directly, delete "despam".[/ref]


    Thanks. I guess something along those lines would work - certainly for
    the example I provided. Unfortunately, the real world example is a
    little more complicated so I was hoping for something a little more
    generic, like php's explode()

    strawberry Guest

  6. #6

    Default Re: exploding strings

    On May 18, 8:30 pm, strawberry <com> wrote: [/ref]
    > [/ref]
    > [/ref]



    >
    > Thanks. I guess something along those lines would work - certainly for
    > the example I provided. Unfortunately, the real world example is a
    > little more complicated so I was hoping for something a little more
    > generic, like php's explode()[/ref]


    Come to think of it, maybe this will be good enough after all. Cheers.

    strawberry Guest

Similar Threads

  1. Replies: 8
    Last Post: September 3rd, 02:48 PM
  2. Exploding fonts in PS7 on Mac OS9
    By BRS369@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 3
    Last Post: April 28th, 01:52 PM
  3. Whoa!! Exploding Slices
    By Snerp in forum Macromedia Fireworks
    Replies: 3
    Last Post: November 19th, 01:49 AM
  4. Exploding Win XP disk
    By Nicholas in forum Windows XP/2000/ME
    Replies: 3
    Last Post: July 24th, 02:31 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139