note 98546 deleted from function.json-encode by danbrown

From: Date: Tue, 22 Jun 2010 12:23:48 +0000
Subject: note 98546 deleted from function.json-encode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170375@lists.php.net to get a copy of this message
Note Submitter: freeublue at yahoo dot com dot au ---- In the face of all the beautiful code above my solution seems way to simple, but in order to understand what is going on in this function, the code follows. From database. <?php include "config.php"; $file = "aac.json"; $fp = fopen($file, "w"); $name = '{"databasetablename":{'; fwrite($fp, $name); fclose($fp); $q = mysql_query("SELECT * FROM databasetablename"); while ($r = mysql_fetch_object( $q) ) { $id = $r->id; $title =$r->title; $ita = $r->ita; $co = $r->co; $se = $r->se; $paw = $r->paw; $img = $r->img; $img2 = $r->img2; $sg = '"' . $id . '":[{"title": "' . $title . '", "ita": "' . $ita . '", "co": "' . $co . '", "se": "' . $se . '", "paw": "' . $paw . '", "img": "' . $img . '", "img2": "' . $img2 . '"}], '; $ft = fopen($file, "a+"); fwrite($ft, $sg); fclose($ft); } $final = '"9000":[{"title": "Cello", "ita": "equip", "co": "whatever", "se": "se", "paw": "paw", "img": "uu", "img2": "img2"}]}}'; $ftg = fopen($file, "a+"); fwrite($ftg, $final); fclose($ftg); ?> validate http://jsonformatter.curiousconcepts.com

« previous php.notes (#170375) next »