I'm having this problem where the php will return duplicate rows in the json echo, it works in the database itself, just the php is messing it up somewhere and I'm unsure where.
<?php
$con = mysql_connect("host","user","pass");
if (!$con)
{
die('could not connect: ' . mysql_error());
}
mysql_select_db("db", $con);
$sql = "SELECT DISTINCT INFO, ( 6364 * acos( cos( radians(55.952) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-3.187) ) + sin( radians(55.952) ) * sin( radians( lat ) ) ) ) AS distance FROM table HAVING distance <0.5 ORDER BY distance LIMIT 0 , 20";
$result = mysql_query($sql,$con);
if (!$result)
{
echo "db error\n";
echo 'MySQL Error : ' . mysql_error();
}
while ($row = mysql_fetch_array($result))
{
$output[]=$row["INFO"]; //added ["INFO"] to protect my location and make the problem easier to see.
echo (json_encode($output));
}
?>
it returns:
["This is where I study"]["This is where I study","this is where I live"]["This is where I study","this is where I live","this is where I could swim"]
i.e. = [0][0,1][0,1,2] where I need it to return simply [0,1,2] for java manipulation.
Thank you in advance, I'm a newb to php/mysql so any comment it welcome.
whileloop... echo after finishing thewhileloop