I have a line of code to convert data from database to JSON. The only problem is that the code I have seems to be dropping the first record. Any thoughts to why.
$return_arr = Array();
$query_qrySelect = "SELECT * FROM table";
$qrySelect = mysql_query($query_qrySelect, $database) or die(mysql_error());
$row_qrySelect = mysql_fetch_assoc($qrySelect);
$totalRows_qrySelect = mysql_num_rows($qrySelect);
while ($row = mysql_fetch_array($qrySelect, MYSQL_ASSOC)) {
array_push($return_arr,$row);
}
echo json_encode($return_arr);
mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the pink box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.