I’m parsing data with JSON from my server database, but the presentation in my list is from the last id to the first. I would like to have the ids from 0 to whatever id I have, for example 20. Is that possible?
This is my php class:
<?
header('content-type: text/html; charset=utf-8');
$link1 = mysql_pconnect("host", "username", "pass") or die("Could not connect");
mysql_select_db("dbname") or die("Could not select database");
$query= mysql_query("SET NAMES 'utf8'");
$rs = mysql_query("select * from vathmoi ORDER BY vathmoi.id DESC");
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
function replace_unicode_escape_sequence($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UTF-16BE');
}
$str = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', json_encode($arr));
echo '{"as_of":"Today!","trends":'.$str.'}';
?>
Change
ORDER BY vathmoi.id DESCtoORDER BY vathmoi.id ASCAlso, look into using PHP’s json_encode function for outputting your JSON string.
Edit: Nevermind, I didn’t see that you were using json_encode in that callback. Not sure why you need that callback… json_encode usually does a pretty good job of escaping your data so that it’s valid JSON, but then again I do not know what data you’re pulling from the DB.