1

I have some trouble here.. I hope somebody could help me.

so let me explain first

Lets say i have this table

idBarang | idAttribute | Value
----------------------------------
1        | 2           | A
2        | 2           | B
3        | 2           | B
4        | 2           | C,D

And then i have this Query Code

select * from relation_barang where idAttribute = '2' GROUP BY value  limit 0,20

My Problem Is, try too look the var_dump of my query result object

array(2) {
  [0]=>
  object(stdClass)#4 (5) {

    ["idBarang"]=>
    string(1) "1"
    ["idAttribute"]=>
    string(1) "2"
    ["value"]=>
    string(14) "A"

  }
    {
  [1]=>
  object(stdClass)#4 (5) {
    ["idBarang"]=>
    string(1) "2"
    ["idAttribute"]=>
    string(1) "2"
    ["value"]=>
    string(1) "B"

  }


[1]=>
      object(stdClass)#4 (5) {
        ["idBarang"]=>
        string(1) "4"
        ["idAttribute"]=>
        string(1) "2"
        ["value"]=>
        string(1) "C,D"

      }

    }

And what wanted is something Like this

array(2) {
      [0]=>
      object(stdClass)#4 (5) {

        ["idBarang"]=>
        string(1) "1"
        ["idAttribute"]=>
        string(1) "2"
        ["value"]=>
        string(14) "A"

      }
        {
      [1]=>
      object(stdClass)#4 (5) {
        ["idBarang"]=>
        string(1) "2"
        ["idAttribute"]=>
        string(1) "2"
        ["value"]=>
        string(1) "B"

      }
 [2]=>
      object(stdClass)#4 (5) {
        ["idBarang"]=>
        string(1) "4"
        ["idAttribute"]=>
        string(1) "2"
        ["value"]=>
        string(1) "C"

      }
[3]=>
      object(stdClass)#4 (5) {
        ["idBarang"]=>
        string(1) "4"
        ["idAttribute"]=>
        string(1) "2"
        ["value"]=>
        string(1) "D"

      }


    }

I try to searching on google but cant find the solution

how to do that? did anyone knows how to do that? im really confused here.. anyone experts help me please,,, thanks

  • 1
    With the query you are running, you should get no results, given the table you provided. Please explain what you want in words. – mavrosxristoforos Sep 27 '13 at 06:35
  • My bads.. iwrite the wrong query.. now i fix my information.. can you help me? – user2070749 Sep 27 '13 at 06:41
  • You shouldn't store values like that. What if you need to remove/edit a value? Think about redesigning your table. – Alasjo Sep 27 '13 at 06:44
  • I only want to edit the table output, look at the 3rd value of the table ("C,D"), i would like to separate that string and make it as object to.. so the object array will become 4.. do you got me? – user2070749 Sep 27 '13 at 06:49
  • 1
    Possible duplicate: http://stackoverflow.com/questions/11100501/split-comma-separated-values-from-one-column-to-2-rows-in-the-results-mysql – mavrosxristoforos Sep 27 '13 at 06:49
  • Ahh, I see what you mean. You want to split the `C,D` into separate array indexes with an SQL query. Unfortunately, SQL doesn't work like that. You should design your database differently, what you want to do is awkward since the data isn't separated properly. Probably it can be done, but there must be a better way to access the values. – Ben Sep 27 '13 at 06:51

0 Answers0