分别获取ajax json数据

时间:2018-06-25 17:27:51

标签: php json ajax

我的代码有一个小问题,可以说我有一个像这样的json:

Select Max(x.price), x.month, x.year from(
   SELECT SUM(price) as price, Year(paymensDate) as year, Month(paymentDate) as month FROM `payments` 
   where idGroup=27 group by Year(paymentDate), Month(paymentDate)
) as x

我想像这样整理数据:

  

John @john john.png

     

Mark @mark mark.png

但是每次数据出来都是这样的:

  

John Mark @john @mark john.png mark.png

这是我的密码:

[{"img":"john.png","name":"John","username":"@john"},
{"img":"mark.png","name":"mark","username":"@mark"}]

这是索引代码:

<?php
class search{
    public function gettingvalues($search_value){
        require_once('conx.php');
        $dir = "usersimage/";
        $sql = "SELECT name,img,username FROM users WHERE username like '$search_value%' || name like '$search_value%'";
        $query = mysqli_query($conx,$sql);
        if ($query) {
            if (mysqli_num_rows($query) > 0) {
                while ($row = mysqli_fetch_array($query)) {
                    $img = $row['img'];
                    $name = $row['name'];
                    $username = $row['username'];
                    $json = array('img' => $img, 'name' => $name, 'username' => $username);
                    $results[] = $json;
                }
                echo json_encode($results);
            }
        }
    }
}
?>

实际上,这是我第一次使用json,我不知道出了什么问题,或者我错过了一些事情,希望得到一些答案。

1 个答案:

答案 0 :(得分:0)

您需要按照显示顺序构建HTML。

{{1}}