I am trying implement a search activity which gets data from a mysql table based on a search.
I want to write a PHP script to use the string entered into the EditText and get the adjacent cell.
For example, Imagine there are two columns of the mysql table: Firstname and surname; I would like to be able to get the surname by searching the Firstname (Entering the Firstname into the EditText. I know this may require a SELECT Surname FROM Names WHERE ... query but how do I indicate the variable from my Java class?
The PHP script so Far:
<?php
mysql_connect("localhost","root","");
mysql_select_db("androidapp");
$sql=mysql_query("SELECT surname WHERE $get'fname'");
while($row=mysql_fetch_assoc($sql)) $output[]=$row;
print(json_encode($output));
mysql_close();
?>
Also, is the HttpGet method appropriate or HttPost method to do this, the result should display the surname in a TextView
i assume you want to send and receive data from php to java (android) through http post or http get. correct me if i am wrong.
basically what you want php to return is the row that matches the first name in the table.
always remember to escape the data for any sql injection with php's
mysql_real_escape_string()function. ans also i would prefer HTTP POST.from your android application you will have to send a http request to the server where the PHP script is.
hope this helps you