I would suggest the use of MySQLi or MySQL PDO for performance and security purposes, but to answer the question:
while($row = mysql_fetch_assoc($result)){
$json[] = $row;
}
echo json_encode($json);
If you switched to MySQLi you could do:
$query = "SELECT * FROM table";
$result = mysqli_query($db, $query);
$json = mysqli_fetch_all ($result, MYSQLI_ASSOC);
echo json_encode($json );
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…