Hello and good day all,
I have try android eclipse project connect to phpmysql with xampp server. For now i success to get and display all data from mysql database to listview.
But how to only get specific data only. Example :
Name : Class: CodeSubject: SubjectName: JOHN 2 TBE124
JOHN 2 TKE123
JOHN 2 TZE125
JOHN 2 TDE194
ADAM 2 TAE154
ADAM 2 TQE114
GORGE 2 TGE164
GORGE 2 TCE123
GORGE 2 TBE126
What i want is ListView will show All JOHN data/row/column if spinner select JOHN. If select ADAM then ListView will show All ADAM data/row/column. For my code now, it will show all the data from database. If any have tutorial related please share with me.
I used androidhive tutorial. http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
<?php
/*
* Following code will list all the products
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
//here the search value is what you send from the app
if(isset($_GET["matricID"])){
$string_input = $_GET['matricID'];
$result = mysql_query("SELECT * FROM tbl_semester WHERE matricID LIKE '%$matricID%'") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["tbl_semester"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$semester = array();
$semester["pid"] = $row["pid"];
$semester["matricID"] = $row["matricID"];
$semester["code"] = $row["code"];
$semester["course"] = $row["course"];
$semester["point"] = $row["point"];
$semester["crdhour"] = $row["crdhour"];
$semester["grdpoint"] = $row["grdpoint"];
$semester["reattempt"] = $row["reattempt"];
$semester["grd"] = $row["grd"];
// push single product into final response array
array_push($response["tbl_semester"], $semester);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
}
?>