Sunteți pe pagina 1din 4

select music_data.

url from music_data,sno_artist_id,artist_composer_id_name wher


e music_data.sno=sno_artist_id.sno;
select music_data.url from music_data join sno_artist_id join artist_composer_id
_name on music_data.sno=sno_artist_id.sno
and sno_artist_id.artist_id = artist_composer_id_name.unique_artist_id where art
ist_name='k k';

<?php
define('HOST','localhost');
define('USER','root');
define('PASS','');
define('DB','androiddb');
$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');

<?php
if($_SERVER['REQUEST_METHOD']=='GET'){
$id = $_GET['id'];
require_once('dbConnect.php');
$sql = "SELECT * FROM colleges WHERE id='".$id."'";
$r = mysqli_query($con,$sql);
$res = mysqli_fetch_array($r);
$result = array();
array_push($result,array(
"name"=>$res['name'],
"address"=>$res['address'],
"vc"=>$res['vicechancellor']
)
);
echo json_encode(array("result"=>$result));
mysqli_close($con);
}

package net.simplifiedcoding.gettingspecificdata;
/**
* Created by Belal on 10/12/2015.
*/
public class Config {
public static final String DATA_URL = "http://192.168.94.1/Android/College/g
etData.php?id=";
public static final String KEY_NAME = "name";
public static final String KEY_ADDRESS = "address";
public static final String KEY_VC = "vc";
public static final String JSON_ARRAY = "result";
}

package net.simplifiedcoding.gettingspecificdata;
import
import
import
import
import
import
import
import

android.app.ProgressDialog;
android.os.Bundle;
android.support.v7.app.AppCompatActivity;
android.view.View;
android.widget.Button;
android.widget.EditText;
android.widget.TextView;
android.widget.Toast;

import
import
import
import
import

com.android.volley.RequestQueue;
com.android.volley.Response;
com.android.volley.VolleyError;
com.android.volley.toolbox.StringRequest;
com.android.volley.toolbox.Volley;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity implements View.OnClickListe
ner {
private EditText editTextId;
private Button buttonGet;
private TextView textViewResult;
private ProgressDialog loading;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
editTextId = (EditText) findViewById(R.id.editTextId);
buttonGet = (Button) findViewById(R.id.buttonGet);
textViewResult = (TextView) findViewById(R.id.textViewResult);
buttonGet.setOnClickListener(this);
}
private void getData() {
String id = editTextId.getText().toString().trim();
if (id.equals("")) {
Toast.makeText(this, "Please enter an id", Toast.LENGTH_LONG).show()
;
return;
}
loading = ProgressDialog.show(this,"Please wait...","Fetching...",false,
false);
String url = Config.DATA_URL+editTextId.getText().toString().trim();
StringRequest stringRequest = new StringRequest(url, new Response.Listen
er<String>() {
@Override
public void onResponse(String response) {
loading.dismiss();
showJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,error.getMessage().toString(),T
oast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
private void showJSON(String response){
String name="";
String address="";
String vc = "";
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
JSONObject collegeData = result.getJSONObject(0);
name = collegeData.getString(Config.KEY_NAME);
address = collegeData.getString(Config.KEY_ADDRESS);
vc = collegeData.getString(Config.KEY_VC);
} catch (JSONException e) {
e.printStackTrace();
}
textViewResult.setText("Name:\t"+name+"\nAddress:\t" +address+ "\nVice C
hancellor:\t"+ vc);
}
@Override

public void onClick(View v) {


getData();
}
}

S-ar putea să vă placă și