osoda osoda - 6 months ago 56
MySQL Question

How to populate an android spinner with data coming from mysql

I already have populated my android spinner with data coming from mysql. But instead of getting 1 data per type i get everything. Example i have 2 basketball in my database, the android spinner shows 2 basketball instead of 1


$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);

$tmp[] = $row;

echo json_encode ($tmp);


Here is the response i get. Instead of getting only 1 value. I get everything from s_name in my android spinner

[{"0":"Basketball","s_name":"Basketball"}, {"0":"Basketball","s_name":"Basketball"},


You can use a group by in your query :

$sql = "select s_name from sport GROUP BY s_name order by s_name asc;";