I'm making an Android application and I need to make a query in sql using php but I do not know why it does not return anything when I ask. This is a java code for Android:
AsyncHttpClient client = new AsyncHttpClient();
final String url="http://pear-web.com/profe.php";
RequestParams requestParams = new RequestParams();
Aplicacion app = (Aplicacion) getApplicationContext();
requestParams.add("login",app.getUsuario());
client.get(url, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
if(statusCode==200)
{
progresDialog.dismiss();
try {
JSONArray jsonArray = new JSONArray(new String(responseBody));
for (i=0;i<jsonArray.length();i++){
Name.add(jsonArray.getJSONObject(i).getString("Login"));
System.out.println(Name);
Apellido.add(jsonArray.getJSONObject(i).getString("apellido"));
Correo_profe.add(jsonArray.getJSONObject(i).getString("Correo_padre"));
ID.add(jsonArray.getJSONObject(i).getString("ID_profe"));
}
listView.setAdapter(new ImagenAdapter(getApplicationContext()));
} catch (JSONException e) {
e.printStackTrace();
}
}
}'
And this is the php code:
<?php
$hostname_localhost="";
$database_localhost="";
$username_localhost="";
$password_localhost="";
$login = $_REQUEST["login"];
$localhost=mysql_connect($hostname_localhost,$username_localhost,
$password_local host)or die ("cannot conect");
mysql_select_db($database_localhost) or die("cannot selet DB");
$sql="SELECT Login,apellido,Correo_padre,ID_profe FROM usuario
WHERE ID_profe=$login "; <---este es el where que menciono
$result = mysql_query($sql,$localhost);
$json = array();
if(mysql_num_rows($result)){
while ($row=mysql_fetch_object($result)) {
$json[]=$row;
}
}
mysql_close($localhost);
echo json_encode($json);
?>
It should be mentioned that when I do not put the Where
it shows me the query, but I want to filter the list when necessary. I already tried everything and I do not know what I'm doing wrong.