I want to retrieve value from mysql database and covert it into json.
<?php
$con = mysql_connect("localhost","name","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$result = mysql_query("SELECT Inc_number FROM Increment WHERE id=1");
while($row = mysql_fetch_array($result))
{
echo $row['Inc_number'];
echo "<br />";
}
mysql_close($con);
$objJSON['sample'] = $result;
$objJSON = json_encode($objJSON);
echo($objJSON);
?>
I get the output like this,
4
{“sample”:null}
I want 4 instead of null. What am i doing wrong here?
Help me please
Thanks,
What you want is
$row['Inc_number'], not$result.