首页 \ 问答 \ 从基于android发送的电子邮件地址的服务器获取具有特定记录的列表视图(get list view with specific records from server based on email address sent from android)

从基于android发送的电子邮件地址的服务器获取具有特定记录的列表视图(get list view with specific records from server based on email address sent from android)

我在服务器中有一个表,我想根据从android java代码发送的电子邮件地址检索特定记录。

电子邮件地址存储在全局变量中,我可以获取其值,但我不知道如何将其值发送到服务器并获取记录。

我的代码检索表中的所有记录

请帮我做,我试着做了3天,但没有解决方案

这是我的PHP代码:

<?php
$objConnect = mysql_connect("****","******","******");
$objDB = mysql_select_db("******");
$strSQL = "SELECT * FROM Appointment ";
$objQuery = mysql_query($strSQL);
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
    $arrCol = array();
    for($i=0;$i<$intNumField;$i++)
    {
        $arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
    }
    array_push($resultArray,$arrCol);
}

mysql_close($objConnect);

echo json_encode($resultArray);
?>    

这是我的java代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.DialogInterface;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class ServicesBMWGarageActivity extends Activity {

private ClipData myClip;

private ClipboardManager myClipboard;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.services_bmw_garage);

    GlobalClass globalVariable = (GlobalClass) getApplicationContext();
    // Get email from global/application context
    final String Email  = globalVariable.getEmail();

    myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);

    // Permission StrictMode
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    // listView1
    final ListView lisView1 = (ListView)findViewById(R.id.listView1);   


    String url = "http://ec2-54-148-64-28.us-west-2.compute.amazonaws.com/Codiad/workspace/BMWdatabase/MyAppointments.php";

    try {

        JSONArray data = new JSONArray(getJSONUrl(url));

        final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> map;

        for(int i = 0; i < data.length(); i++){
            JSONObject c = data.getJSONObject(i);

            map = new HashMap<String, String>();
            map.put("A_ID", c.getString("A_ID"));
            map.put("A_Model", c.getString("A_Model"));
            map.put("A_Services", c.getString("A_Services"));
            map.put("A_DATE", c.getString("A_DATE"));
            MyArrList.add(map);

        }


        SimpleAdapter sAdap;
        sAdap = new SimpleAdapter(ServicesBMWGarageActivity.this, MyArrList, R.layout.activity_column,
                new String[] {"A_ID", "A_Model", "A_Services", "A_DATE"}, new int[] {R.id.ColMemberID, R.id.ColName, R.id.ColTel,R.id.Coldate });      
        lisView1.setAdapter(sAdap);

        final AlertDialog.Builder viewDetail = new AlertDialog.Builder(this);
        // OnClick Item
        lisView1.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> myAdapter, View myView,
                    int position, long mylng) {

                String A_ID1 = MyArrList.get(position).get("A_ID")
                        .toString();
                String Type1 = MyArrList.get(position).get("A_Model")
                        .toString();
                String Model1 = MyArrList.get(position).get("A_Services")
                        .toString();
                String Model2 = MyArrList.get(position).get("A_DATE")
                        .toString();
                final String phoneNumber = MyArrList.get(position).get("A_ID")
                        .toString();
                //String sMemberID = ((TextView) myView.findViewById(R.id.ColMemberID)).getText().toString();
                // String sName = ((TextView) myView.findViewById(R.id.ColName)).getText().toString();
                // String sTel = ((TextView) myView.findViewById(R.id.ColTel)).getText().toString();

                viewDetail.setIcon(android.R.drawable.btn_star_big_on);
                viewDetail.setTitle("Appointment Detail");
                viewDetail.setMessage("ID : " + A_ID1 + "\n"
                        + "Vehicle Model : " + Type1 + "\n" + "Service Type : " + Model1
                        + "\n" + "Date : " + Model2);
                viewDetail.setPositiveButton("OK",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                // TODO Auto-generated method stub
                                String text = phoneNumber;
                                myClip = ClipData.newPlainText("text", text);
                                myClipboard.setPrimaryClip(myClip);
                                Toast.makeText(getApplicationContext(), "Appointment ID Copied", 
                                Toast.LENGTH_SHORT).show();

                                dialog.dismiss();
                            }
                        });
                viewDetail.show();

            }
        });


    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}


public String getJSONUrl(String url) {
    StringBuilder str = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) { // Download OK
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                str.append(line);
            }
        } else {
            Log.e("Log", "Failed to download results..");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return str.toString();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_activity_home_page, menu);
    return true;
}

}

I have a table in the server and I want to retrieve specific records based on email address sent from android java code.

The email address is stored in global variable and I can get its value but I don't know how to send its value to the server and get the records.

my code retrieves all the records from the table

Please Help me to do it, I tried to do it for 3 days but with no solution

this is my PHP code :

<?php
$objConnect = mysql_connect("****","******","******");
$objDB = mysql_select_db("******");
$strSQL = "SELECT * FROM Appointment ";
$objQuery = mysql_query($strSQL);
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
    $arrCol = array();
    for($i=0;$i<$intNumField;$i++)
    {
        $arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
    }
    array_push($resultArray,$arrCol);
}

mysql_close($objConnect);

echo json_encode($resultArray);
?>    

this is my java code :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.DialogInterface;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class ServicesBMWGarageActivity extends Activity {

private ClipData myClip;

private ClipboardManager myClipboard;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.services_bmw_garage);

    GlobalClass globalVariable = (GlobalClass) getApplicationContext();
    // Get email from global/application context
    final String Email  = globalVariable.getEmail();

    myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);

    // Permission StrictMode
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    // listView1
    final ListView lisView1 = (ListView)findViewById(R.id.listView1);   


    String url = "http://ec2-54-148-64-28.us-west-2.compute.amazonaws.com/Codiad/workspace/BMWdatabase/MyAppointments.php";

    try {

        JSONArray data = new JSONArray(getJSONUrl(url));

        final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> map;

        for(int i = 0; i < data.length(); i++){
            JSONObject c = data.getJSONObject(i);

            map = new HashMap<String, String>();
            map.put("A_ID", c.getString("A_ID"));
            map.put("A_Model", c.getString("A_Model"));
            map.put("A_Services", c.getString("A_Services"));
            map.put("A_DATE", c.getString("A_DATE"));
            MyArrList.add(map);

        }


        SimpleAdapter sAdap;
        sAdap = new SimpleAdapter(ServicesBMWGarageActivity.this, MyArrList, R.layout.activity_column,
                new String[] {"A_ID", "A_Model", "A_Services", "A_DATE"}, new int[] {R.id.ColMemberID, R.id.ColName, R.id.ColTel,R.id.Coldate });      
        lisView1.setAdapter(sAdap);

        final AlertDialog.Builder viewDetail = new AlertDialog.Builder(this);
        // OnClick Item
        lisView1.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> myAdapter, View myView,
                    int position, long mylng) {

                String A_ID1 = MyArrList.get(position).get("A_ID")
                        .toString();
                String Type1 = MyArrList.get(position).get("A_Model")
                        .toString();
                String Model1 = MyArrList.get(position).get("A_Services")
                        .toString();
                String Model2 = MyArrList.get(position).get("A_DATE")
                        .toString();
                final String phoneNumber = MyArrList.get(position).get("A_ID")
                        .toString();
                //String sMemberID = ((TextView) myView.findViewById(R.id.ColMemberID)).getText().toString();
                // String sName = ((TextView) myView.findViewById(R.id.ColName)).getText().toString();
                // String sTel = ((TextView) myView.findViewById(R.id.ColTel)).getText().toString();

                viewDetail.setIcon(android.R.drawable.btn_star_big_on);
                viewDetail.setTitle("Appointment Detail");
                viewDetail.setMessage("ID : " + A_ID1 + "\n"
                        + "Vehicle Model : " + Type1 + "\n" + "Service Type : " + Model1
                        + "\n" + "Date : " + Model2);
                viewDetail.setPositiveButton("OK",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                // TODO Auto-generated method stub
                                String text = phoneNumber;
                                myClip = ClipData.newPlainText("text", text);
                                myClipboard.setPrimaryClip(myClip);
                                Toast.makeText(getApplicationContext(), "Appointment ID Copied", 
                                Toast.LENGTH_SHORT).show();

                                dialog.dismiss();
                            }
                        });
                viewDetail.show();

            }
        });


    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}


public String getJSONUrl(String url) {
    StringBuilder str = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) { // Download OK
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                str.append(line);
            }
        } else {
            Log.e("Log", "Failed to download results..");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return str.toString();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_activity_home_page, menu);
    return true;
}

}

原文:https://stackoverflow.com/questions/26978666
更新时间:2022-10-10 17:10

最满意答案

将特定日期捕捉到特定周的元素是weekday()函数。 因此,您需要将输入调整为工作日功能一天,然后在最后添加一天减少补偿。

所以你需要:

=J1-WEEKDAY(J1)+13

代替:

 =J1-WEEKDAY(J1+1)+14

The element that snaps a particular day to a particular week is the weekday() function. So you need to adjust the input to weekday function by one day and then compensate by adding one less day at the end.

So you need:

=J1-WEEKDAY(J1)+13

Instead of:

 =J1-WEEKDAY(J1+1)+14

相关问答

更多
  • 假设这些是标准的Unix时间戳,您可以以任何方式简单地提取/修改日期。 如果您的工作周对应于标准日历周,则更容易: SELECT user_id, clock_in-clock_out FROM yourtable GROUP BY WEEK(FROM_UNIXTIME(clock_in)) 这将只是一周的分组,但这只是为了给你一个大致的想法。 MySQL有各种各样的日期/时间函数可用于此: http : //dev.mysql.com/doc/refman/5.5/en/date-and-time-fu ...
  • 您必须设置deadline时间(17:00),而不是获取当前时间,您可以使用startOf()和set()时刻,只需将以下代码添加到代码中即可: deadline.startOf('day').set({h: 17}); 通过这种方式,您将17:00:00设置为deadline ,您将获得所需的输出。 这里有个完整的例子: console.log(timeLeft()); function timeLeft() { var dayINeed = 5; // for Friday va ...
  • 我不明白为什么你把日期存储为数字而不是字符串,因为你不能对它进行数学运算而你只需将其转换为字符串来解析它。 所以我只想在这个答案中使用字符串日期。 此外,将日期转换为NSDate而不考虑一天内的时间是危险的,因为它在某些时区内往往会产生错误的答案 。 所以让我们告诉解析器使用正午作为一天中的时间: extension NSDate { class func withYMDString(string: String) -> NSDate { let dateFormatter = NS ...
  • BlueSnap最近发布了Apple Pay集成,并于2017年6月4日上线。 您可以在我们的开发人员中心找到文档页面,在此链接下: https : //developers.bluesnap.com/docs/apple-pay 祝你好运! BlueSnap recently released the Apple Pay integration and it went live on June 4th, 2017. You can find the documentation page in our De ...
  • 将特定日期捕捉到特定周的元素是weekday()函数。 因此,您需要将输入调整为工作日功能一天,然后在最后添加一天减少补偿。 所以你需要: =J1-WEEKDAY(J1)+13 代替: =J1-WEEKDAY(J1+1)+14 The element that snaps a particular day to a particular week is the weekday() function. So you need to adjust the input to weekday function ...
  • 如果您想保留当前的设计,只需添加另一个字段即增量序列号。 使用序列号和当前字段的组合,您可以达到下一个或上一个付款期 If you would like to keep your current design, you can simply add another field which is an incremental sequence number. Using combination of sequence number and current fields you can reach the ne ...
  • 我同意Evert的说法,单个RRULE是不可能的。 但是,您可以通过多个RRULE的组合实现这一目标。 这样您就可以将事件分成多个事件,每个事件都有一个以下RRULE: 如果星期三是一个月的最后一天或倒数第二天,我们的星期五将是下个月的第一天或第二天 FREQ=MONTHLY;BYMONTHDAY=1,2;BYDAY=1FR 在31天的几个月中,最后一个星期三的最早日期是25日,所以下周五将是第27-31天之一: FREQ=MONTHLY;BYMONTH=1,3,5,7,8,10,12;BYMONTHDA ...
  • 我不确定我是否在追随你,但是下一个星期五我会得到: $date = Get-Date for($i=1; $i -le 7; $i++) { if($date.AddDays($i).DayOfWeek -eq 'Friday') { $date.AddDays($i) break } } I'm not sure I'm following you but here's I would get next Friday: $date ...
  • 我想到的第一个解决方案是: $dt = new DateTime(); $dt->modify('next friday'); // Next friday from now $dt->modify('next friday'); // Next friday from next friday echo $dt->format('Y-m-d'); 或者,正如您在帖子中暗示的功能: function next_dispatch_date($timestamp){ $dt = new DateTim ...
  • 我会使用一个参数作为开始日期,并计算结束日期为6天(如果需要)。 对于参数,我将为数据创建一个字段,同时使用数据的单个开始日期字段。 参数查询: DECLARE @START_DATE DATE = '01/01/2016' DECLARE @END_DATE DATE = '10/31/2016' ;WITH GETDATES AS ( SELECT @START_DATE AS THEDATE UNION ALL SELECT ...

相关文章

更多

最新问答

更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)