note 98545 deleted from function.json-encode by visualmind

From: Date: Tue, 22 Jun 2010 09:03:39 +0000
Subject: note 98545 deleted from function.json-encode by visualmind
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170371@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 (#170371) next »