我已经使用来自mysql的数据填充了我的android微调器。但是,不是每种类型获得1个数据,而是获得一切。例如我在我的数据库中有2个篮球,android微调器显示2个篮球而不是1个
PHP
$sql = "select s_name from sport order by s_name asc;";
$con = mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name);
$result = mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result))
{
$tmp[] = $row;
}
echo json_encode ($tmp);
mysqli_close($con);
?>
以下是我得到的回复。而不是只获得1个值。我从我的android spinner
中获取s_name中的所有内容[{"0":"Basketball","s_name":"Basketball"}, {"0":"Basketball","s_name":"Basketball"},
{"0":"Basketball","s_name":"Basketball"},
答案 0 :(得分:1)
您可以在查询中使用group by
:
$sql = "select s_name from sport GROUP BY s_name order by s_name asc;";