Sort JSON data by datetime from MySQL data in PHP -


i've got mysql database populated data received youtube api v3. i've managed output data json file below code, want have data outputted descending order of date , time. json string named "publishedat" , format "2015-03-26 15:59:35". i've tried various other similar answers , cannot seem work usort function, wondering if help. i'm new php try , specific possible, please.

thanks.

<?php //open connection mysql db $connection = mysqli_connect("host","username","password","dbname") or die("error " . mysqli_error($connection));  //fetch table rows mysql db $sql = "select * database"; $result = mysqli_query($connection, $sql) or die("error in selecting " . mysqli_error($connection));  // perform query , store result $result = $connection->query($sql);  //create array $songarray = array(); while($row =mysqli_fetch_object($result)) {     $songarray[] = $row; }  echo json_encode($songarray); //close db connection mysqli_close($connection);  $fp = fopen('jsondata.json', 'w'); fwrite($fp, json_encode($songarray)); fclose($fp); ?> 

i suggest modify sql query sort returned data datetime.

depending on table structure need like:

$sql = "select * database order date_column_name"; 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -

Why does a .NET 4.0 program produce a system.unauthorizedAccess error on a Windows Server 2012 machine with .NET 4.5 installed? -