- Previous thread: [PHP] Does anyone know how gettext works under the hood?
- Next thread: [PHP] Removing empty values from array
- Threads sorted by date: php 200906
On Thu, 2009-06-25 at 15:20 -0400, Matt Giddings wrote:
> I know this is the off topic (sorry), but it is a php project that I'm
> working on! I need some pointers on how to pivot a mysql column (containing
> comma delimited data) into an equal number of rows (see example). Any
> direction (pointers to links, etc. would be appreciated).
>
> From this:
>
> user.table
> uid|name|groups
> 1|mcgiddin|1,4,7,10,12
>
>
> To this:
>
> pivot.table
> uid|group
> 1|1
> 1|4
> 1|7
> 1|10
> 1|12
I don't know of any fancy ways of doing it just in MySQL, but if the
records are all as simple as that, something like this should do the
trick:
$query = "SELECT * FROM `user`";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$uid = $row['uid'];
$groups = explode(','$row['groups']);
for($i=0; $i
> I know this is the off topic (sorry), but it is a php project that I'm
> working on! I need some pointers on how to pivot a mysql column (containing
> comma delimited data) into an equal number of rows (see example). Any
> direction (pointers to links, etc. would be appreciated).
>
> From this:
>
> user.table
> uid|name|groups
> 1|mcgiddin|1,4,7,10,12
>
>
> To this:
>
> pivot.table
> uid|group
> 1|1
> 1|4
> 1|7
> 1|10
> 1|12
I don't know of any fancy ways of doing it just in MySQL, but if the
records are all as simple as that, something like this should do the
trick:
$query = "SELECT * FROM `user`";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$uid = $row['uid'];
$groups = explode(','$row['groups']);
for($i=0; $i
Conversations: [PHP] OT mysql pivot table problem
- [PHP] OT mysql pivot table problem by Matt Giddings on 2009-06-25T19:31:45+00:00
- Re: [PHP] OT mysql pivot table problem by Ashley Sheridan on 2009-06-25T19:52:56+00:00
- Re: [PHP] OT mysql pivot table problem by Matt Giddings on 2009-06-25T20:12:45+00:00
- Re: [PHP] OT mysql pivot table problem by Eddie Drapkin on 2009-06-25T20:18:50+00:00
- Re: [PHP] OT mysql pivot table problem by Andrew Ballard on 2009-06-25T20:24:02+00:00
- Re: [PHP] OT mysql pivot table problem by Ashley Sheridan on 2009-06-25T20:25:29+00:00
- Re: [PHP] OT mysql pivot table problem by Andrew Ballard on 2009-06-25T21:15:52+00:00
- Re: [PHP] OT mysql pivot table problem by Matt Giddings on 2009-06-26T14:59:00+00:00
- Re: [PHP] OT mysql pivot table problem by Shawn McKenzie on 2009-06-26T15:11:07+00:00
Related Threads
- Can't Boot or Rescue - redhat
- V Beauty Grand Opening Promotions - I lost 20kg at V Beauty!!! - debian
- shell scripting, how to auto-timeout? - freebsd
- Byte oriented data types in python - python
- Page crawling and URL grabbing - ruby
- Multiple relay_recipient_maps Makefile - postfix
- [users] Update from OpenOffice 3 to 3.0.1 - openoffice
- Graphics tablet / Xorg / mouse problems - freebsd