Skip to content

Instantly share code, notes, and snippets.

@rileypaulsen
Created July 31, 2013 20:32
Show Gist options
  • Save rileypaulsen/6125875 to your computer and use it in GitHub Desktop.
Save rileypaulsen/6125875 to your computer and use it in GitHub Desktop.
generate JSON with rows grouped by a specific column
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("coins");
$result = mysql_query("select * from coins");
$list = array();
while ($r = mysql_fetch_object($result)) {
$list[$r->society][] = $r->ID;
}
print_r(json_encode($list));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment