dqxafj6830 2014-11-22 21:28
浏览 65
已采纳

如何从MySQL发布并从MySQL app获取特定id的数据

How to load data from MySQL for specific id. What I mean is when I click on gridview item 1 to load what I need for this item from MySQL. Currently I have

    $objConnect = mysql_connect("localhost","user","pass");
$objDB = mysql_select_db("database");
$strSQL = "SELECT * FROM table";
$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 obviously load everything from that table. But what if I want when I click on list item_1 to load some query like select * from table where clickeditem = 1 ? I guess I must post it to the .php script but how?

I don't know which part of JAVA code is needed so please tell me if you need and I will post it. Updated: @Override protected Void doInBackground(String... params) { // TODO Auto-generated method stub

        String url = "file.php";

        JSONArray data;
        try {
            resultServer = getJSONUrl(url);
            data = new JSONArray(resultServer);

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

            for(int i = 0; i < data.length(); i++){
                JSONObject c = data.getJSONObject(i);
                map = new HashMap<String, Object>();
                map.put("id", (String)c.getString("id"));
                map.put("name", (String)c.getString("name"));
                map.put("price", (String)c.getString("price"));
                map.put("weight", (String)c.getString("weight"));

                // Thumbnail Get ImageBitmap To Bitmap
                map.put("ImagePathThum", (String)c.getString("image"));
                map.put("ImageThumBitmap", (Bitmap)loadBitmap(c.getString("image")));

                // Full (for View Full)
                map.put("ImagePathFull", (String)c.getString("image_big"));

                MyArrList.add(map);
            }


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

        return null;
    }

UPDATE with sql.

    $strSQL = "SELECT m.id, name, image, image_big, weight, price 
        FROM posts m 
        JOIN packet_r mr 
        ON m.id = mr.id 
        WHERE packed_id = 1";
  • 写回答

1条回答 默认 最新

  • doufu2396 2014-11-23 13:10
    关注

    If I understand your problem correctly, you would indeed need to post it to the php script. And that's very easy:

    static String url = "https://yourlink.com/database.php?clickeditem=1";
    

    Then you can edit your php code like:

    $clickeditem = $_GET['clickeditem'];
    $strSQL = "SELECT * FROM table WHERE clickeditem = '$clickeditem'";
    

    To edit this in your java code simply add:

    "https://yourlink.com/database.php?clickeditem=" + variable;
    

    to your link with the variable to be set when a specific gridview item is clicked.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器