Re: Array expert needed! (long)



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:
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"
Yuk!

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' ]
)
}
}

?>
.



Relevant Pages

  • Re: Array expert needed! (long)
    ... First rule of databases - normalize your data. ... You should have multiple tables to handle this information. ...
    (comp.lang.php)
  • Re: Array expert needed! (long)
    ... First rule of databases - normalize your data. ...  You should have multiple tables to handle this information.. ...
    (comp.lang.php)
  • Re: creating cubes from different data sources Analysis Services 2005
    ... If you think you can synchronize multiple datasources into AS then its ... because your source databases are clean, ... you can't create a cube using different DSV (so no ... another option is to create an empty database in SQL Server and create ...
    (microsoft.public.sqlserver.olap)
  • Re: how to find phase shift between two signals
    ... is not a multiple of the sampling frequency (make sure that enough ... how do you normalize it? ... Normalization is taken care of by the polar form of the spectrum ... XCOR doesn't multiply the signals. ...
    (comp.dsp)
  • Re: "Field Cannot Be Updated" Error
    ... Unfortunately, based on the underlying rules of databases, you cannot ... update a value in a form (or query) based on a query that draws on ... Table Source: Multiple tables ...
    (microsoft.public.access.forms)