2

私はこれを数日間機能させるのに苦労しています。私が欲しいのは、googlecharts で列/棒グラフを作成することです。そして、それをデータベースから動的に生成します。

私のクエリ:

SELECT gs.league as league
             , (Select Count(*) From gamestats WHERE season=gs.season AND league=gs.league AND event=1) as one
             , (Select Count(*) From gamestats WHERE season=gs.season AND league=gs.league AND event=2) as two
             , (Select Count(*) From gamestats WHERE season=gs.season AND league=gs.league AND event=3) as three
             , (Select Count(*) From gamestats WHERE season=gs.season AND league=gs.league AND event=4) as four
             , (Select Count(*) From gamestats WHERE season=gs.season AND league=gs.league AND event=5) as five
             , (Select Count(*) From gamestats WHERE season=gs.season AND league=gs.league AND event=6) as six
           FROM gamestats gs WHERE gs.season=2013 AND gs.league < 3 GROUP by gs.league

json_encode($result) しようとすると、間違った種類のjson形式が表示されます。これは私が今得るものです:

[{"league":"2","one":"9","two":"3","three":"9","four":"2","five":"8","six":"12"},{"league":"4","one":"1","two":"0","three":"0","four":"1","five":"1","six":"2"}]

それでは何も生まれません。GoogleChart の例では、json は次のようになります。

{
"cols": [
  {"id":"","label":"Topping","pattern":"","type":"string"},
    {"id":"","label":"Slices","pattern":"","type":"number"}
  ],
  "rows": [
    {"c":[{"v":"Mushrooms","f":null},{"v":3,"f":null}]},
    {"c":[{"v":"Onions","f":null},{"v":1,"f":null}]},
    {"c":[{"v":"Olives","f":null},{"v":1,"f":null}]},
    {"c":[{"v":"Zucchini","f":null},{"v":1,"f":null}]},
    {"c":[{"v":"Pepperoni","f":null},{"v":2,"f":null}]}
  ]
}

クエリからそのような json 形式を取得するにはどうすればよいですか? ありがとう!

4

1 に答える 1