Convert object to an array so i can sort it?
<p>I have a object i that i list in HTML tables. But i want to able to click different columns in this table to "sort" the the data based on that field in question.</p>

<p>As I'm aware of objects are not sorted, so i need to convert it to an array some how ? And then i use href links to call a sort function to sort the array before repopulating the table.</p>

<p>Was hopeing some one may be able to shed light to explain how i do it ?</p>

<p>This is basically how far i got:</p>

<pre><code>$get = mysql_query("SELECT * FROM game_buildings") or die(mysql_error());
        $i = 0;
        while($row = mysql_fetch_assoc($get)){
            $data[$i][0] = $row['name'];
            $data[$i][1] = $row['id'];
            $i ++;
            }
$data = json_encode($data);
?&gt;
&lt;script&gt;var data = &lt;?echo $data; ?&gt;; &lt;/script&gt;
</code></pre>

<p>Then the table:</p>

<pre><code>&lt;table id="list" style="width:70%;margin: 0 auto;" border="1"&gt;
    &lt;tr&gt;
  &lt;td align="center"&gt;
        &lt;a href="#" onclick='javascript:sort('name')'&gt;Name&lt;/a&gt;
      &lt;/td&gt;
  &lt;td align="center"&gt;
        &lt;a href="#" onclick='javascript:sort('type')'&gt;Type&lt;/a&gt;
      &lt;/td&gt;
    &lt;/tr&gt;

&lt;script&gt;
  for(var key in data){
    result += '&lt;tr&gt;&lt;td&gt;'+data[key][0]+'&lt;/td&gt;&lt;td&gt;'+data[key][1]+'&lt;/td&gt;&lt;/tr&gt;';
  }
    document.getElementById('list').innerHTML += result;
&lt;/script&gt;


&lt;/table&gt;
</code></pre>
