1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Ho to Split String using query and return an array ?

Discussion in 'Databases' started by a4academics, May 14, 2013.

  1. #1
    I need help in solving a query.

    In Hobbies column of Employee table , different Hobbies of each employee is stored. An example is as shown below
    "Reading,Sports,Trekking"

    I need a query to split the string and find the second hobby of an employee. I tried instr to find ",". But was not not able to proceed beyond that. Can anyone suggest a query to split a string and return as array.
     
    a4academics, May 14, 2013 IP
  2. abhijitnumber1

    abhijitnumber1 Member

    Messages:
    19
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    38
    #2
    $a = strstr('Reading,Sports,Trekking', ',');//get the first [SIZE=14px][FONT=verdana][COLOR=#000000]occurrence of a string ( ,Sports,Trekking)[/COLOR][/FONT][/SIZE]
     
    $b = explode(',',trim($a, ','));//delete the ' , ' from both side, split the string by ',' & store the value in variable $b
    echo $b[0];
    PHP:
     
    abhijitnumber1, Jul 3, 2013 IP