I am executing sql query
in phpmyadmin.
Here I have faculty table in database which has Fname
and Fdept
fields.
My PHP file is:-
include("configuration.php");
$dept = $_GET['Dept'];
$sql = mysqli_query($con,"SELECT Fname from faculty WHERE Fdept = '$dept'");
$data = "";
while ($row = mysqli_fetch_assoc($sql)) {
$data = $data.$row['Fname'].":";
}
$data1="SUCCESS:".$data;
echo "{'query_result':'$data1'}";
?>
So, here I am fetching the faculty names by referring their department..
query_result
returns
data of faculty names.
example:
query_result:SUCCESS:John:Nishant:Nawaz
by that i can split each name using split method.. like:
String[] parts = query_result.split(":");
for(int i=0; i<parts.length; i++)
{
System.out.println(parts[i]);
}
output :
SUCCESS
John
Nishant
Nawaz
But how can I assign each name to different string variables, without using index like
String a = part[0];
String b = part[1];
String c = part[2];
Because query result size will be dynamic and if i use this this there will be a ArrayIndexBoundException
occurs
So, how can I use that data by storing it into different string variable,
by that I can put each variable to sharedPreferences
and use it in other activities