Web Design Tips

Thursday, September 24, 2009

PHP Tip

Need to create JSON quickly?
Using PHP/MySQL?
Use PHP 5.2.* json_encode function.

$query = mysql_query($sql);

// using the json_encode of php 5.2.*
while($object= mysql_fetch_object($query)){
$encodable[] = $object;
}

$encoded = json_encode($encodable);

echo $encoded;

This PHP Tip is provided by Chris Coppenbarger.

Last modified on GMT. 0 comments. Top.

Comments are closed.

toolbar powered by Conduit