我正在开发一个 android 应用程序。我需要从远程 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.idLEFT Join tb_sports sp1 ON sp1.id_sport = spo.sport_spotLEFT JOIN tb_spot_types st ON st.id_spot_type = spo.type_spotLEFT 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_spotGROUP 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; }脚本正常工作,至少在从浏览器执行时是这样。它显示了 10 个项目。问题是当应用程序调用时,它会发送 15 个项目。我想问题一定出在 GROUP BY spo.id_spot 行上。如果未按 spo.id_spot 分组,查询将显示 15 个项目。但是我不明白 PHP 在浏览器上直接执行时是否有效。
- 1 回答
- 0 关注
- 119 浏览
添加回答
举报
0/150
提交
取消