FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

changing Array format from result of MySQL

 


Mgccl
here is what MySQL returns in a visual way..
Code:

game_id | team_id | stat_id
1 | 1 | 1
1 | 2 | 3
1 | 3 | 7
1 | 3 | 6
2 | 1 | 1
2 | 4 | 3


here is what I know
in records with the same game_id, there will be no repeating team_id
in records with the same team_id, there will be no repeating stat_id

so, after I got the query, I made them into this format
Code:
$data['$rownumber']['game_id']
$data['$rownumber']['teat_id']
$data['$rownumber']['stat_id']

but now, I want turn it into this format
we assume $int_1 and $int_2 could be any interger
Code:
$data['$rownumber']['game_id']
$data['$rownumber'][$int_1]['team_id']
$data['$rownumber'][$int_1][$int_2]['stat_id']


and the requirement is, in the array of $data['$rownumber'], there will be only different team_id that belong to the game_id of $data['$rownumber']. and each $data['$rownumber'][$int_1][$int_2]['stat_id'] need to be belong to $data['$rownumber'][$int_1][$team_id']


any one got a way to do that because I have already drained my mind and only get as far as making them into

Code:
$data[$'rownumber']['game_id']
$data['$rownumber'][$int_1]['team_id']
$data['$rownumber'][$int_1]['stat_id']


for example, this

Code:
$data[1]['game_id'] = 1;
$data[1]['team_id']= 1;
$data[1]['stat_id'] =1;

$data[2]['game_id'] = 1;
$data[2]['team_id'] = 1;
$data[2]['stat_id'] =2;

$data[3]['game_id'] =1;
$data[3]['team_id'] =2;
$data[3]['stat_id'] =3;


will be into this

Code:
$data[1]['game_id'] =1
$data[1][1]['team_id'] = 1;
$data[1][1][1]['stat_id'] =1;
$data[1][1][2]['stat_id'] =2;
$data[1][2]['team_id'] = 2;
$data[1][2][1]['stat_id'] = 3;


and my brain are buring right now Sad, please some one help me
btw, would converting a larger group
(say, 50 rows, each game id refer to 4 teams, each team refer to 2 stats)
taking a very long time(like... more than 3 seconds)

thx
Philip
this is some of my own script, i think u wanna be like this.

Code:
      $query=mysql_query("SELECT * FROM `table` where user_id=".$userdata['user_id'],$dbz);
      $row = mysql_fetch_row($query);
      $i=0;
      while ($i < mysql_num_fields($query))
      {
         $data_right[strtoupper(mysql_field_name($query, $i))]=$row[$i];
         $i++;
      }
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.