franzwarning Posted March 15, 2011 Share Posted March 15, 2011 Hi, here is my script to get the usernames of a few members. I'm trying to encode it using JSON. <?php require("connect.php"); $date = date("Y-m-d"); $picarray = array(); $handle = opendir ('pqimages/'.$date.'/'); while (false !== ($file = readdir($handle))) { if($file != "." && $file != "..") { $getusername = mysql_query("SELECT * FROM users WHERE lastupload='pqimages/".$date."/".$file."'"); while ($row = mysql_fetch_assoc($getusername)){ $usernames= $row['username']; $people = array(); $people[] = $usernames; echo json_encode($people); } } } ?> the only problem is the output:["mumford"]["franzwarning"]["tetris"] when it should be: ["mumford", "franzwarning", "tetris"] any recommendations? Thanks, George Quote Link to comment https://forums.phpfreaks.com/topic/230675-json-encoding/ Share on other sites More sharing options...
gristoi Posted March 15, 2011 Share Posted March 15, 2011 Try moving $people = array(); Just before your while loop. At the moment you are creating a new array on every loop instead off adding to one array Quote Link to comment https://forums.phpfreaks.com/topic/230675-json-encoding/#findComment-1187687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.