Re: Array expert needed! (long)
- From: amygdala <example@xxxxxxxxxxx>
- Date: Fri, 23 Jan 2009 22:26:33 +0100
mouac01@xxxxxxxxx schreef:
On Jan 23, 11:03 am, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:moua...@xxxxxxxxx wrote:On Jan 22, 5:08 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:Yuk!What's the data being retrieved from the database look like?Here's what it looks like. Thanks...
"sort","obj_owner","obj_type","obj_id","obj_name"
"1","John","Tables",1,"Sales"
"1","John","Reports",5,"by Region and Product"
"1","John","Reports",2,"for Dylan"
"1","John","Reports",3,"for Evelyn"
"1","John","Reports",4,"for Mary"
"1","John","Reports",1,"for Nathan"
"1","John","Charts",1,"Column Chart"
"2","Mary","Tables",2,"Games I Play"
First rule of databases - normalize your data. This is far from
normalized. You should have multiple tables to handle this information.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@xxxxxxxxxxxxx
==================- Hide quoted text -
- Show quoted text -
I believe my tables are normalized. This out is what the stored
procedure returns. Sorry for being unclear. Thanks...
You could do something like the following (or split your routine up in multiple database queries perhaps):
not tested btw, and not very elegant, but hey ;)
<?php
$myArray = array();
// let's assume $result is the DB resultset
foreach( $result as $row )
{
if( !isset( $myArray[ $row[ 'obj_owner' ] ] ) )
{
$myArray[ $row[ 'obj_owner' ] ] = array(
'label' => $row[ 'obj_owner' ],
'children' => array()
)
}
if( !isset( $myArray[ $row[ 'obj_owner' ] ][ 'children' ][ $row[ 'obj_type' ] ] ) )
{
$myArray[ $row[ 'obj_owner' ] ][ 'children' ][ $row[ 'obj_type' ] ] = array(
'label' => $row[ 'obj_type' ],
'children' => array()
)
}
if( !isset( $myArray[ $row[ 'obj_owner' ] ][ 'children' ][ $row[ 'obj_type' ] ][ 'children' ][ $row[ 'obj_name' ] ] ) )
{
$myArray[ $row[ 'obj_owner' ] ][ 'children' ][ $row[ 'obj_type' ] ][ 'children' ][ $row[ 'obj_name' ] ] = array(
'label' => $row[ 'obj_name' ],
'data' => $row[ 'obj_id' ]
)
}
}
?>
.
- Follow-Ups:
- Re: Array expert needed! (long)
- From: mouac01@xxxxxxxxx
- Re: Array expert needed! (long)
- References:
- Array expert needed! (long)
- From: mouac01@xxxxxxxxx
- Re: Array expert needed! (long)
- From: Jerry Stuckle
- Re: Array expert needed! (long)
- From: mouac01@xxxxxxxxx
- Re: Array expert needed! (long)
- From: Jerry Stuckle
- Re: Array expert needed! (long)
- From: mouac01@xxxxxxxxx
- Array expert needed! (long)
- Prev by Date: Re: Array expert needed! (long)
- Next by Date: Re: general question: printing html tables
- Previous by thread: Re: Array expert needed! (long)
- Next by thread: Re: Array expert needed! (long)
- Index(es):
Relevant Pages
|