本帖最后由 sigkl00181 于 2015-04-22 14:15:39 编辑
<br /> $question = $_GET['question'];<br /> $arr = explode("|",$question);<br /> for($i = 0;$i <= 3; $i++){<br /> $rid = $arr[$i];<br /> $sql = "select * from xs_radio where rid = '$rid'";<br /> $result = mysql_query($sql);<br /> $arr = array();<br /> while($row = mysql_fetch_array($result, MYSQL_ASSOC)){<br /> $ar[] = $row; <br /> }<br /> $js = json_encode($ar);<br /> echo $js;<br /> }<br />
Nach dem Login kopieren
这是查询的语句
<br />[{"rid":"1","title":"\u6211\u662f\u8c01","a":"\u5b8b\u5411\u4e1c","b":"\u9b4f\u4eae","c":"\u738b\u514b\u5a07","d":"\u5b8b\u5b50\u6587","answer":"\u5b8b\u5411\u4e1c"}]<br />[{"rid":"2","title":"\u6211\u662f\u8c01","a":"\u9b4f\u4eae","b":"\u5218\u5fb7\u534e","c":"\u674e\u5a1c","d":"\u5f20\u626c","answer":"\u9b4f\u4eae"}]<br />[{"rid":"3","title":"\u6211\u662f\u8c01","a":"\u9b4f\u4eae","b":"\u738b\u514b\u5a07","c":"\u674e\u56fd\u4f1f","d":"\u738b\u83f2","answer":"\u738b\u514b\u5a07"}]<br />[{"rid":"16","title":"\u6211\u662f\u8c01","a":"\u5218\u5f66\u5bbe","b":"\u674e\u56fd\u632f","c":"\u7a0b\u79c0\u82b9","d":"\u738b\u514b\u5a07","answer":"\u738b\u514b\u5a07"}]<br />
Nach dem Login kopieren
查询出来的结果。 如何把这三个json组合成一个?
<br />[{"rid":"1","title":"\u6211\u662f\u8c01","a":"\u5b8b\u5411\u4e1c","b":"\u9b4f\u4eae","c":"\u738b\u514b\u5a07","d":"\u5b8b\u5b50\u6587","answer":"\u5b8b\u5411\u4e1c"},<br />{"rid":"2","title":"\u6211\u662f\u8c01","a":"\u9b4f\u4eae","b":"\u5218\u5fb7\u534e","c":"\u674e\u5a1c","d":"\u5f20\u626c","answer":"\u9b4f\u4eae"},<br />{"rid":"3","title":"\u6211\u662f\u8c01","a":"\u9b4f\u4eae","b":"\u738b\u514b\u5a07","c":"\u674e\u56fd\u4f1f","d":"\u738b\u83f2","answer":"\u738b\u514b\u5a07"},<br />{"rid":"16","title":"\u6211\u662f\u8c01","a":"\u5218\u5f66\u5bbe","b":"\u674e\u56fd\u632f","c":"\u7a0b\u79c0\u82b9","d":"\u738b\u514b\u5a07","answer":"\u738b\u514b\u5a07"}]<br />
Nach dem Login kopieren
保存成这样的。
------解决思路----------------------转数组 然后合成一个数组 再转json
------解决思路----------------------把 $ar[] = $row;
改为 $ar[$i][] = $row;
把
$js = json_encode($ar);
echo $js;
移到 for 循环后面