この投稿の最終編集者は 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 />
ログイン後にコピー
これはクエリ ステートメントの結果です
<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 />
ログイン後にコピー
。これら 3 つの JSON を 1 つに結合するにはどうすればよいでしょうか?
<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 />
ログイン後にコピー
このように保存します。
------解決策----------------------配列を変換し、それを組み合わせて配列を変換し、json
-----解決策のアイデア----------------------Put $ar [] = $ row;
は $ar[$i][] = $row;
は
$js = json_encode($ar);
echo $js;
から for ループ後