gpt4 book ai didi

php - PHP 脚本在浏览器和 Android 应用程序中的不同输出

转载 作者:行者123 更新时间:2023-11-29 02:20:00 27 4
gpt4 key购买 nike

我正在开发一款安卓应用。

我需要从远程 MySQL 数据库中检索数据。

我正在使用以下 PHP 脚本将 JSON 数组发送到应用程序:

<?php 

require_once 'dbconnect.php';
$con->set_charset("utf8");

//Checking if any error occured while connecting
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}

//creating a query
$stmt = $con->prepare("SELECT spo.id_spot,spo.sport_spot,spo.type_spot,spo.date_upload_spot,spo.description_spot,spo.city_spot,spo.country_spot,spo.latitud_spot,
spo.longitud_spot,spo.verified_spot,spo.verified_spot_by,spo.short_name,mediaspottype,mediaspotfiles,st.name_spot_type,st.logo_spot_type,st.diametro_spot_type FROM tb_spots spo

LEFT join users u ON spo.uploaded_by = u.id

LEFT Join tb_sports sp1 ON sp1.id_sport = spo.sport_spot
LEFT JOIN tb_spot_types st ON st.id_spot_type = spo.type_spot
LEFT JOIN tb_spot_media pme On pme.media_spot = spo.id_spot
LEFT JOIN (
SELECT media_spot, GROUP_CONCAT(media_type) AS mediaspottype ,GROUP_CONCAT(media_file) AS mediaspotfiles
FROM tb_spot_media
GROUP BY media_spot
) AS pm ON pm.media_spot = spo.id_spot
GROUP BY spo.id_spot

");

//executing the query
$stmt->execute();

//binding results to the query
$stmt->bind_result($id_spot,$sport_spot,$type_spot,$date_upload_spot,$description_spot,$city_spot,$country_spot,$latitud_spot,
$longitud_spot,$verified_spot,$verified_spot_by,$short_name,$mediaspottype,$mediaspotfiles,$name_spot_type,$logo_spot_type,$diametro_spot_type);

$products = array();

//traversing through all the result
while($stmt->fetch()){
$temp = array();
$temp['id_spot'] = $id_spot;
$temp['sport_spot'] = $sport_spot;
$temp['type_spot'] = $type_spot;

$temp['date_upload_spot'] = $date_upload_spot;
$temp['description_spot'] = $description_spot;
$temp['city_spot'] = $city_spot;
$temp['country_spot'] = $country_spot;
$temp['latitud_spot'] = $latitud_spot;
$temp['longitud_spot'] = $longitud_spot;
$temp['verified_spot'] = $verified_spot;
$temp['verified_spot_by'] = $verified_spot_by;
$temp['short_name'] = $short_name;
$temp['mediaspottype'] = $mediaspottype;
$temp['mediaspotfiles'] = $mediaspotfiles;
$temp['name_spot_type'] = $name_spot_type;
$temp['logo_spot_type'] = $logo_spot_type;
$temp['diametro_spot_type'] = $diametro_spot_type;
array_push($products, $temp);
}

//displaying the result in json format
echo json_encode($products);

脚本正常工作,至少在从浏览器执行时是这样。它显示 10 个项目。

问题是当应用程序调用时,它会发送 15 个项目。

我想问题一定出在 GROUP BY spo.id_spot 行。

如果未按 spo.id_spot 分组,查询将显示 15 个项目。

但我不明白如果 PHP 在浏览器上直接执行时能正常工作会出现什么问题。

这是安卓部分:

private void loadspots() {


StringRequest stringRequestspots = new StringRequest(Request.Method.GET, URL_SPOTS,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
//converting the string to json array object
spotsArray = new JSONArray(response);
editor.putString("spotsArray", spotsArray.toString() );
editor.apply();





} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
});

//adding our stringrequest to queue

Volley.newRequestQueue(this).add(stringRequestspots);

最佳答案

我已经解决了禁用 Volley 缓存的问题。

关于php - PHP 脚本在浏览器和 Android 应用程序中的不同输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56851615/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com