FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Roll SQL name value query into two-dimensional array
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Roll SQL name value query into two-dimensional array [message #175199] Mon, 22 August 2011 01:35 Go to previous message
Richard A. DeVenezia is currently offline  Richard A. DeVenezia
Messages: 1
Registered: August 2011
Karma:
Junior Member
I have a query that returns name value pairs in groups.

data
g n v
1 a 1
1 b 2
1 c 3
3 a 10
3 b 9
3 c 8

want
x[0] = array('a'=>1,'b'=>2,'c'=>3);
x[1] = array('a'=>10,'b'=>9,'c'=>8);

this is close but x is ending up empty

$q = 'select g,n,v from some_view order by g,some_seq_id';
$result = db_query($q); // in drupal

$x=array();
$map=array();
$prior_g = -1;
while ($obj = db_fetch_object($result)) {
if ($rec->g != $prior_g) {
//append a new map
$map=$array();
$x[] = $map;
$prior_g = $rec->g;
}
// fill in the map as we roll through the name value pairs within
the group
$map[$rec->n] = $rec->v;
}

print "<pre>".print_r($x,1)."</pre>";

shows
Array
(
[0] => Array
(
)

[1] => Array
(
)
)


So what is going wrong ?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: MySQL date time current time diffenece
Next Topic: different servers, different results with a file upload
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 02:09:16 GMT 2024

Total time taken to generate the page: 0.04093 seconds