I have a query where output from unique option getting repeated in while loop belp query with mysql dump
CREATE TABLE `txt` (
`option` varchar(10) NOT NULL,
`username` varchar(100) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `txt` VALUES ('a', 'ashok');
INSERT INTO `txt` VALUES ('a', 'sachin');
INSERT INTO `txt` VALUES ('b', 'parvez');
query:
$result = mysql_query("SELECT option, name from txt");
while ($row = mysql_fetch_array($result)) {
$option = $row['option'];
$name = $row['username'];
$array[$option] = $name;
}
print_r($array);
Actual output:
Array ( [a] => Array ( [name] => Array ( [0] => ashok [1] => sachin )
Array ( [b] => Array ( [name] => Array ( [0] => ashok [1] => sachin [2] => parvez)
Expected output:
Array ( [a] => Array ( [name] => Array ( [0] => ashok [1] => sachin )
Array ( [b] => Array ( [name] => Array ( [0] => parvez)
Please tell me what mistake I have made in this query