• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Query to json - HELP

#1
[eluser]Near[/eluser]
Hi! I have a table named product containing this value
p_id | p_name | p_quantity
1 p1 10
2 p2 20
3 p1 5
4 p1 6

how would i get the records like this?

p1 [10,5,6]
p2 [20]

and then convert it to json.. Thanks!

#2
[eluser]ojcarga[/eluser]
I don´t know if that is possible, but I´d do it this way,

Code:
$this->output
    ->set_content_type('application/json')
    ->set_output(json_encode(array('foo' => 'bar')));

array('foo' => 'bar') is the array containing the data retrieved from the database.

http://ellislab.com/codeigniter/user-gui...utput.html

#3
[eluser]CroNiX[/eluser]
Look into MySQLs group_concat() function.

#4
[eluser]Near[/eluser]
[quote author="CroNiX" date="1335896855"]Look into MySQLs group_concat() function.[/quote]


hi thanks! Group_concat do the trick on my problem. I thought i need to use json on that. Anyways! Thanks again..


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.