现在我正在做预订申请。因此,我尝试将变量发送到php并提取与我发送的变量匹配的行。具体来说,将userbranch从androidstudio发送到php,并提取coursebranch与userbranch具有相同值的行。我使用where来设置条件,但它无法检索数据。
这是我的php代码(courselist.php)
<?php
header("Content-Type: text/html; charset=UTF-8");
$con = mysqli_connect($host, $username, $pwd, $db) or die('Unable to connect');
$courseBranch = $_GET["userBranch"]
if(mysqli_connect_error($con))
{
echo "Failed to Connect to Database".mysqli_connect_error();
}
$sql = "SELECT courseID, courseTeacher, courseDay, courseTime, courseBranch FROM COURSE WHERE courseBranch = '$courseBranch'";
$result = mysqli_query($con,$sql);
if ($result)
{
while ($row = mysqli_fetch_array($result))
{
$flag[] = $row;
}
print(json_encode($flag));
}
mysqli_close($con);
?>
这是我的android studio代码,在这里解析数据
<?php
private int parseData(){
try {
JSONArray ja = new JSONArray(jsonData);
JSONObject jo = null;
courseTeacher.clear();
courseDay.clear();
courseTime.clear();
courseTeacherParse.clear();
for(int i = 0; i <ja.length();i++)
{
jo = ja.getJSONObject(i);
int id = jo.getInt("courseID");
String name = jo.getString("courseTeacher");
String day = jo.getString("courseDay");
String time = jo.getString("courseTime");
String branch = jo.getString("courseBranch");
course = new Course();
course.setCourseTeacher(name);
course.setCourseDay(day);
course.setCourseTime(time);
courseTeacher.add(name);
courseDay.add(day);
courseTime.add(time);
courseBranch.add(branch);
} catch (JSONException e) {
e.printStackTrace();
}
?>
这是地址
<?php
String urlAddress = "";
try {
urlAddress = "http://show981111.cafe24.com/CourseList.php?userBranch=" + URLEncoder.encode(userBranch, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
暂无答案!
目前还没有任何答案,快来回答吧!