json showing duplicate output of mysql result

json, php

Solution

This is because the default behavior of `mysql_fetch_array()` is to return both a column name and index keyed array.

Use `mysql_fetch_assoc()` or set the second parameter of `mysql_fetch_array()`.

while($r = mysql_fetch_assoc($result)) {
    $dataArray[] = $r;
}

Problem

I am trying to print json_encode and I get output duplicated. I am certain there is one single record in database and yet it shows the same record data twice in various format. This is it: ``` [{"0":"Polo","name":"Polo","1":"City ","location":"City ","2":"Manama","city":"Manama"}] ``` The code behind this is: ``` $dataArray = array(); while($r = mysql_fetch_array($result)) { $dataArray[] = $r; } print json_encode($dataArray, JSON_UNESCAPED_UNICODE); ``` Any idea?

Original source